How to know element position while it move

This question already has an answer here:

  • Get mouse position within div? [duplicate] 3 answers
  • Retrieve the position (X,Y) of an HTML element 23 answers

  • 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.

    链接地址: http://www.djcxy.com/p/15608.html

    上一篇: 如何捕捉x和y的位置,并精确地在MVC4中重新定位?

    下一篇: 移动时如何知道元素的位置