开发者

Triggering a JavaScript click() event at specific coordinates

开发者 https://www.devze.com 2022-12-30 17:31 出处:网络
Trying to fire off (trigger) a click event. Its easy to do in jQuery, but cannot figure out how to set the coordinates of the event and send them开发者_StackOverflow社区 along.

Trying to fire off (trigger) a click event. Its easy to do in jQuery, but cannot figure out how to set the coordinates of the event and send them开发者_StackOverflow社区 along.

Essentially, I need to trigger a click at a specific location (which is calculated prior to the trigger() call).

Any way to do this (in jQuery or otherwise)?

Thanks -


Set the pageX and pageY properties (which are normalized) on the event object and pass it to .trigger(), like this:

var e = new jQuery.Event("click");
e.pageX = 10;
e.pageY = 10;
$("#elem").trigger(e);


The ".trigger()" call accepts an "extraParameters" parameter that you could use to stuff the XY coords in I would think. Documentation

.trigger("click", [x, y]);
0

精彩评论

暂无评论...
验证码 换一张
取 消