问题
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