Reputation: 12663
I'd like to register a mousemove
callback and immediately trigger that callback with the current mouse x/y position. Currently I'm doing this:
$('body').mousemove(hoverFunction).mousemove();
But hoverFunction
's event receives undefined values for pageX and pageY as documented. Is there a clean way I can handle this besides having a mousemove
callback that updates a global mouse position variable?
Upvotes: 2
Views: 4736
Reputation: 781
You need to create a jQuery.Event
object and set pageX
and pageY
properties on it directly. Then trigger this event on $(document)
. See this StackOverflow question.
Upvotes: 3
Reputation: 77976
$('body').bind('mousemove',function(e){
hoverFunction(e);
});
$(function(){
$('body').trigger('mousemove');
});
Upvotes: 0