Document.elementFromPoint


Responding to occasions with JavaScript is the structure of a vibrant experiences on the internet. Whether it’s a click occasion or another common action, reacting to that action is very important. We began with designating occasions to particular components, then relocated to occasion delegation for performance, however did you understand you can recognize components by position on the page? Let’s take a look at document.elementFromPoint and document.elementsFromPoint

The document.elementFromPoint technique accepts x and y specifications to recognize the top-most component at a point:

const component = document.elementFromPoint( 100, 100);.
// 

If you need to know the whole component stack, you can utilize document.elementsFromPoint:

const components = document.elementsFromPoint( 100, 100);.
// [
, , ]

The elementFromPoint and elementsFromPoint are actually useful for experiences where designers do not wish to designate private occasions. Games and home entertainment websites might gain from these functions. How would you utilize them?


Like this post? Please share to your friends:
Leave a Reply

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: