mouseenter鼠标事件

本文详细介绍了JavaScript中mouseenter和mouseover两个鼠标事件的区别。mouseenter事件仅在鼠标进入元素本身时触发,不考虑子元素,而mouseover事件在鼠标经过元素及其子元素时都会触发。由于mouseenter不冒泡,因此它不会在子元素上重复触发。通过示例代码演示了这两个事件的不同行为,帮助开发者更好地理解和使用这两个事件。
摘要由CSDN通过智能技术生成

mouseenter鼠标事件

1.当鼠标移动到元素上时就会触发mouseenter事件

2.类似mouseover,它们两者之间的差别是

mouseover鼠标经过自身盒子会触发,经过子盒子还会触发。mouseenter只会经过自身盒子触发

这样的原因就是 mouseenter不会冒泡。

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			.father {
				width: 300px;
				height: 300px;
				background-color: pink;
			}
			
			.son {
				width: 200px;
				height: 200px;
				background-color: skyblue;
			}
			
			.w {
				margin: 100px auto;
			}
		</style>
	</head>
	<body>
		<div class="father w">
			<div class="son w">
				
			</div>
		</div>
		<script type="text/javascript">
			var father = document.querySelector('.father');
			var son = document.querySelector('son');
			father.addEventListener('mouseenter',function() {
				console.log(11);
			})
		</script>
	</body>
</html>

mouseover鼠标划过这两个盒子公共部分一次:

mouseenter鼠标划过 这两个盒子公共部分一次:

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hcoke

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值