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鼠标划过 这两个盒子公共部分一次: