1、mouseover和mouseout的效果是对应的;mouseenter和mouseleave的效果是对应的。
2、两者在使用时若没有子元素,效果是相同的。
3、mouseover和mouseout在从父元素进入子元素或从子元素移除到父元素时都会触发。
4、mouseenter和mouseleave只与父元素相关,与子元素不相关,更常用。
复制下方实例,可在浏览器中体验两者区别
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
.container{
width: 500px;
height: 500px;
background: red;
}
.child{
display: inline-block;
width: 300px;
height: 300px;
margin: 100px;
background: green;
}
</style>
</head>
<body>
<div class="container"
onmouseover="eventFn('over')"
onmouseout="eventFn('out')"
onmouseleave="eventFn('leave')"
onmouseenter="eventFn('enter')">
<div class="child"></div>
</div>
</body>
<script type="text/javascript">
function eventFn(type){
console.log(type)
}
</script>
</html>