Is there a way to trigger mousemove and get event.pageX, event.pageY?

后端 未结 6 1734
温柔的废话
温柔的废话 2020-12-05 23:23

So, like the question specifies, is there a way to trigger a mousemove event in jQuery which also sends the mouse coordinates to the event Object?

So far my code can

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 00:13

    You cannot move a mouse if that is what you're asking. But you could call a function with whatever context and arguments you want. E.g.:

    function foobar(e)
    {
      this.className = 'whatever'; // this == element
    }
    
    someElement.onmousemove = foobar;
    
    var obj = {whatever:'you want'};
    foobar.call(someElement, obj); // calls foobar(obj) in context of someElement
    

提交回复
热议问题