English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The event.pageY property returns the position of the mouse pointer relative to the top (upper edge) of the document, in pixels.
This property is usually used withevent.pageXused together with the property.
event.pageY
Display the position of the mouse relative to the left edge and top edge of the document:
$("document").mousemove(function(event){ $("#output").text("pageX: " + event.pageX + ", pageY: " + event.pageY); });Test and see‹/›
Change the position of DIV relative to the mouse position:
$("document").ready(function(){ let pos = {x:0, y:0}; let box = $("div"); let w = box.width(); let h = box.height(); let offset = box.position(); $("document").mousemove(function(event){ pos.x = event.pageX - offset.left - (w/2); pos.y = event.pageY - offset.top - (h/2); box.css({"left":pos.x, "top":pos.y}); }); });Test and see‹/›
Parameter | Description |
---|---|
event | TheEventThe parameters come from the event binding feature |