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>
上一篇:面试官:方法重写时需要注意哪些问题?


下一篇:Go get LibreSSL SSL_connect: SSL_ERROR_SYSCALL