How to know element position while it move
This question already has an answer here:
The pageX
/ pageY
variables in the event
object refers to the mouse position. If you want to get the position of the element you should do something like this:
$(document).on('mousemove', function(e) {
var element = $('#myDiv');
console.log( element.offset() );
// returns an object with x/y coordinates of the top-left corner of the element
});
Checkout the documentation for .offset()
for more info.
上一篇: 如何捕捉x和y的位置,并精确地在MVC4中重新定位?
下一篇: 移动时如何知道元素的位置