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