onmousemove 事件
实例
将鼠标指针移到 <div> 元素上时执行 JavaScript:
<div onmousemove="myFunction()">Move the cursor over me</div>
亲自试一试 »
页面下方有更多实例。
定义和用法
onmousemove 事件当指针在元素上移动时发生 。
浏览器支持
事件 | |||||
---|---|---|---|---|---|
onmousemove | Yes | Yes | Yes | Yes | Yes |
语法
注释: Internet Explorer 8 或更早的版本不支持 addEventListener() 方法。
技术细节
是否支持冒泡: | Yes |
---|---|
是否支持取消: | Yes |
事件类型: | MouseEvent |
支持的 HTML 标签: | 所有 HTML 元素,除了: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title> |
DOM 版本: | Level 2 Events |
更多实例
实例
这个例子演示了 onmousemove、onmouseenter 和 mouseover 事件之间的区别:
<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>
亲自试一试 »
<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>
实例
This example demonstrates the difference between the 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>
亲自试一试 »
<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>