mouseout、mouseover和mouseleave、mouseenter区别
结论:
mouseenter:当鼠标移入某元素时触发。
mouseleave:当鼠标移出某元素时触发。
mouseover:当鼠标移入某元素时触发,移入其子元素时也会触发。
mouseout:当鼠标移出某元素时触发,移出其子元素时也会触发。
mousemove:鼠标在某元素上移动时触发,即使在其子元素上也会触发。
mouseout、mouseover和mouseleave、mouseenter最大的区别,在于mouseleave、mouseenter子元素连带触发。
优先级:
mouseout > mouseover > mouseenter = mouseleave >mousemove
例子:
<!DOCTYPE html>
<html>
<head lang="en"><meta charset="UTF-8"><title></title><style>.a{width: 500px;height: 500px;background: aliceblue;}.b{width: 200px;height: 200px;background: beige;}.c{width: 100px;height: 100px;background: violet;}</style>
</head>
<body><div class="a">A<div class="b"οnmοuseenter="mouseenter()"οnmοuseleave="mouseleave()"οnmοuseοut="mouseout()"οnmοuseοver="mouseover()"οnmοusemοve="mousemove()">B<div class="c">C</div></div></div><script>function mouseenter(){console.log('mouseenter')}function mouseleave(){console.log('mouseleave')}function mouseout(){console.log('mouseout')}function mouseover(){console.log('mouseover')}function mousemove(){console.log('mousemove')}</script>
</body>
</html>
效果:
操作: