onmousemove 事件 | HTML DOM 事件对象

返回到:DOM 对象:HTML DOM 事件对象

定义和用法

onmousemove 事件会在鼠标指针移到指定的对象时发生。

语法

在HTML中:

<element onmousemove="SomeJavaScriptCode">

在Js里:

object.onmousemove=function(){SomeJavaScriptCode};
参数描述
SomeJavaScriptCode必需。规定该事件发生时执行的 JavaScript。

所有主要浏览器都支持 onmousemove 事件

支持该事件的 HTML 标签:

onmousemove 属性可用于使用 HTML 元素,除了: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>。

实例

在鼠标指针移到指定的元素后执行Javascript代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>Web176教程(Web176.com)</title>
<script>
function bigImg(x){
	x.style.height="64px";
	x.style.width="64px";
}
function normalImg(x){
	x.style.height="32px";
	x.style.width="32px";
}
</script>
</head>
<body>

<img onmousemove="bigImg(this)" onmouseout="normalImg(this)" border="0" src="/images/logo.svg" alt="Smiley" width="32" height="32">
<p>函数 bigImg() 在鼠标指针移动到笑脸图片是触发。</p>
<p>函数 normalImg() 在鼠标指针移出笑脸图片是触发。</p>

</body>
</html>

作者:terry,如若转载,请注明出处:https://www.web176.com/javascriptbook/domtips/3875.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2021年9月24日 下午3:30
下一篇 2021年9月24日 下午3:37

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注