其他分享
首页 > 其他分享> > mousemove和moseenter的区别(学习笔记)

mousemove和moseenter的区别(学习笔记)

作者:互联网

mousemove触发时会发生冒泡,子元素也会触发事件
mouseenter不出触发事件冒泡,对应mouseleave

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .father {
            width: 200px;
            height: 200px;
            background-color: pink;
        }
        .son {
            width: 100px;
            height: 100px;
            background-color: yellow;
        }
    </style>
</head>
<body>
    <div class="father">
        <div class="son"></div>
    </div>
    <script>
        var father = document.querySelector('.father');
        //mouseover会发生冒泡,移动到子元素的时候也会触发事件
        //mouseenter 不会发生冒泡
        father.addEventListener('mouseenter',function(){
            console.log('11');
        })
    </script>
</body>
</html>

标签:触发,color,100px,father,笔记,mousemove,冒泡,moseenter,mouseenter
来源: https://blog.csdn.net/weixin_45842954/article/details/122150581