JavaScript: The Definitive Guide, Sixth Editio javaScript权威指南(第6版) pdf 文字版-文字版, javascript电子书, 和javascript 有关的电子书:

15.8.3 Determining the Element at a Point

15.8.3 Determining the Element at a Point


The getBoundingClientRect() method allows us to determine the current position of an element in a viewport. Sometimes we want to go in the other direction and determine which element is at a given location in the viewport. You can determine this with the elementFromPoint() method of the Document object. Pass X and Y coordinates (using viewport coordinates, not document coordinates) and this method returns an Element object that is at the specified position. At the time of this writing, the algorithm for selecting the element is not specified, but the intent of this method is that it returns the innermost and uppermost (see the CSS z-index attribute in §16.2.1.1 ) element at that point. If you specify a point that is outside of the viewport, elementFromPoint() will return null even if that point would be perfectly valid when converted to document coordinates.

elementFromPoint()seems like a very useful method, and the obvious use case is passing the coordinates of the mouse pointer to determine which element the mouse is over. As we’ll learn in Chapter 17 , however, mouse event objects already include this information in their target property. In practice, therefore, elementFromPoint() is not commonly used.

欢迎转载,转载请注明来自一手册:http://yishouce.com/book/1/31433.html
友情链接It题库(ittiku.com)| 版权归yishouce.com所有| 友链等可联系 admin#yishouce.com|粤ICP备16001685号-1