目录

onmousemove 事件

示例

将鼠标指针移动到 <div> 元素上时调用函数:

<div onmousemove="myFunction()">Move the cursor over me</div>
亲自试一试 »

下面有更多示例。


描述

这个onmousemove事件发生时指针在元素上移动

鼠标事件

Event Occurs When
onclick The user clicks on an element
oncontextmenu The user right-clicks on an element
ondblclick The user double-clicks on an element
onmousedown A mouse button is pressed over an element
onmouseenter The pointer is moved onto an element
onmouseleave The pointer is moved out of an element
onmousemove The pointer is moving over an element
onmouseout The mouse pointer moves out of an element
onmouseover The mouse pointer is moved over an element
onmouseup The mouse button is released over an element

也可以看看:

鼠标事件对象

教程:

JavaScript 事件


语法

在 HTML 中:

< element onmousemove=" myScript">
亲自试一试 »

在 JavaScript 中:

object.onmousemove = function(){ myScript};
亲自试一试 »

在 JavaScript 中,使用 addEventListener() 方法:

object.addEventListener("mousemove", myScript);
亲自试一试 »


技术细节

气泡: 是的
可取消: 是的
事件类型: 鼠标事件
HTML 标签: 所有 HTML 元素,除了:<base>、<bdo>、<br>、<head>、<html>、<iframe>、<meta>、<param>、<script>、<style> 和 <title>
DOM 版本: 2 级活动

更多示例

示例

此示例演示了 onmousemove、onmouseenter 和 mouseover 事件之间的区别:

<div onmousemove="myMoveFunction()">
  <p id="demo1">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>
亲自试一试 »

示例

此示例演示了 onmousemove、onmouseleave 和 onmouseout 事件之间的区别:

<div onmousemove="myMoveFunction()">
  <p id="demo1">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>
亲自试一试 »

浏览器支持

onmousemove是 DOM Level 2 (2001) 功能。

所有浏览器都完全支持它:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes 9-11