Coordinates of mouse events in JavaScript
문제
I would like to create a mouse event manually on an point, knowing its coordinates. I use this function :
$(document.elementFromPoint(x, y)).mousedown();
The click is used by a function that needs the pageX
and pageY
properties of the event, but it does not work because the created event doesn't have these properties.
Does anybody know why?
Thank you!
해결책
Simply create a jQuery event with the required properties an pass it over to the "trigger function":
var event = jQuery.Event("mousedown", {pageX: x, pageY: y});
$(document.elementFromPoint(x, y)).trigger(event);
That should work.
제휴하지 않습니다 StackOverflow