onmousemove event | mousemove event
Occurs when the user moves the mouse over the element.
Use the onmouseover event to receive a notification when the user moves the mouse pointer into and the onmouseout event to receive a notification when the user moves the mouse pointer out of an element.
Note: the onmousemove event is not fired during a drag operation. For that case, use the ondragover event.
How to register:
In HTML:
In JavaScript:
<ELEMENT onmousemove="handler"> |
In JavaScript:
object.onmousemove = handler; | |||||||||||
object.addEventListener ("mousemove", handler, useCapture); |
| ||||||||||
object.attachEvent ("onmousemove", handler); |
You can find the related objects in the Supported by objects section below.
The event object is accessible to all event handlers in all browsers.
The properties of the event object contain additional information about the current event.
To get further details about these properties and the possible event handler registration methods, please see the page for the event object.
For a complete list of events, see the page for Events in JavaScript. |
Basic information:
Bubbles | Yes |
Cancelable | No |
Event object | MouseEvent |
Actions that invoke the onmousemove event:
- Moving the mouse pointer out of an element.
The order of events related to the onmousemove event:
Internet Explorer | Firefox, Opera, Google Chrome, Safari |
---|---|
|
|
Example HTML code 1:
This example illustrates the use of the onmousemove event:
|
||||
<head> <style> #flying { position: fixed; } </style> <!--[if lte IE 6]> <style> #flying { position: absolute; /* ie6 does not support fixed position */ } </style> <![endif]--> <script type="text/javascript"> function UpdateFlyingObj (event) { var mouseX = Math.round (event.clientX); var mouseY = Math.round (event.clientY); var flyingObj = document.getElementById ("flying"); flyingObj.style.left = mouseX + "px"; flyingObj.style.top = mouseY + "px"; } </script> </head> <body onmousemove="UpdateFlyingObj (event);"> <div style="height:1000px;">The flying object also works for document scrolling.</div> <img id="flying" src="flying.gif" /> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example dumps the order of events while the mouse moves into, over and out of an element:
|
||||
<head> <script type="text/javascript"> function DumpInfo (event) { var info = document.getElementById ("info"); info.innerHTML += event.type + ", "; } </script> </head> <body> <div style="background-color:#d0f0a0; width:200px" onmouseover="DumpInfo (event)" onmouseenter="DumpInfo (event)" onmousemove="DumpInfo (event)" onmouseout="DumpInfo (event)" onmouseleave="DumpInfo (event)"> Move your mouse pointer into and out of this element! </div> <br /><br /> <div id="info" style="background-color:#f0f0ff; font-weight:bold;"></div> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
document, window
HTML elements:
a, abbr, acronym, address, applet, area, b, bdo, big, blink, blockquote, body, button, caption, center, cite, code, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, h1, h2, h3, h4, h5, h6, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, listing, map, marquee, menu, nobr, noframes, object, ol, optgroup, option, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tbody, td, textarea, tfoot, th, thead, tr, tt, u, ul, var, xmp
Related pages:
External links:
onmousemove (MSDN)
onmousemove (Mozilla Developer Center)
onmousemove (Safari Reference Library)
onmousemove (W3C)
onmousemove (Mozilla Developer Center)
onmousemove (Safari Reference Library)
onmousemove (W3C)
User Contributed Comments