Where does this MouseEvent property come from?

拟墨画扇 提交于 2019-12-11 12:33:28

问题


I have this jsfiddle which reports the x,y coordinates of a white square that is being moved around by the mouse when the mouse button is released.

http://jsfiddle.net/35z4J/115/

This part of the code helps to report the x,y coordinates of the centre of the square.

stop: function(e) {
  console.log("STOPPING");
    var divheight= e.path[0].offsetHeight;
    var divWidth= e.path[0].offsetWidth;
    console.log(e.clientX+divWidth/2)
     console.log(e.clientY+divheight/2)

},

The 2 lines of code from the above that puzzles me are;

var divheight= e.path[0].offsetHeight;
var divWidth= e.path[0].offsetWidth;

I looked at the MouseEvent documentation. https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent I cannot find anything about path.offsetHeight and path.OffsetWidth. What are those? Where can I find the relevant documentation?


回答1:


The path is a property of the event object which contains all the ancestors in tree order.

See Dispatching events

If event’s target attribute value is participating in a tree, let event path be a static ordered list of all its ancestors in tree order, and let event path be the empty list otherwise.

So e.path[0] will refer to the element from where the event was originated. Then the Element has the offsetHeight property



来源:https://stackoverflow.com/questions/32942707/where-does-this-mouseevent-property-come-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!