mouseover:鼠标经过自身盒子会触发,经过子盒子还会触发
mouseenter:只会在鼠标经过自身盒子才会触发 跟 mouseleave 鼠标离开 搭配
原理:mouseenter与mouseleave不会冒泡,mouseover会冒泡
<head>
<style>
.father {
width: 300px;
height: 300px;
background-color: pink;
margin: 100px auto;
}
.son {
width: 200px;
height: 200px;
background-color: purple;
}
</style>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
<script>
var father = document.querySelector(".father");
var son = document.querySelector(".son");
father.addEventListener("mouseenter", function () {
console.log(11);
});
// father.addEventListener("mouseover", function () {
// console.log(11);
// });
</script>
</body>
</html>