onmousemove Event
Definition and Usage
The onmousemove event occurs when the pointer moves over an element.
Example
Example 1
When the mouse cursor is moved over the <div> element, execute JavaScript:
<div onmousemove="myFunction()">Move the cursor over me</div>
Example 2
This example demonstrates the difference between onmousemove, onmouseenter, and mouseover events:
<div onmousemove="myMoveFunction()"> <p id="demo">I will demonstrate onmousemove!</p> </div> <div onmouseenter="myEnterFunction()"> <p id="demo2">I will demonstrate onmouseenter!</p> </div> <div onmouseover="myOverFunction()"> <p id="demo3">I will demonstrate onmouseover!</p> </div>
Example 3
This example demonstrates the difference between onmousemove, onmouseleave, and onmouseout events:
<div onmousemove="myMoveFunction()"> <p id="demo">I will demonstrate onmousemove!</p> </div> <div onmouseleave="myLeaveFunction()"> <p id="demo2">I will demonstrate onmouseleave!</p> </div> <div onmouseout="myOutFunction()"> <p id="demo3">I will demonstrate onmouseout!</p> </div>
Syntax
In HTML:
<element onmousemove="myScript">
In JavaScript:
object.onmousemove = function(){myScript};
In JavaScript, use the addEventListener() method:
object.addEventListener("mousemove", myScript);
Note:Internet Explorer 8 or earlier versions do not support addEventListener() method.
Technical details
Bubbling: | Support |
---|---|
Cancellable: | Support |
Event types: | MouseEvent |
Supported HTML tags: | All HTML elements except: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style> and <title> |
DOM Version: | Level 2 Events |
Browser Support
Events | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
onmousemove | Support | Support | Support | Support | Support |