JavaScript-229:mouseover和mouseenter区别

在这里插入图片描述](https://img-blog.csdnimg.cn/b0acf37537254ad28519c95e08b378d9.png)
![在这里插入图片描述

mouseover 鼠标经过自身盒子会触发 经过子盒子还会触发
mouseenter 只有经过自身盒子触发 因为不会冒泡
mouseleave 鼠标离开触发 同样不会冒泡

结构

   <div class="father">
       <div class="son"></div>
   </div>

CSS

        .father {
    
    
            width: 200px;
            height: 200px;
            background-color: pink;
            margin: 0 auto;
        }

        .son {
    
    
            width: 100px;
            height: 100px;
            background-color: red;
        }

js

        var father = document.querySelector('.father');
        var son = document.querySelector('.son')
        // father.addEventListener('mouseover', function () {
    
    
        //     console.log(11);

        // })
        // father.addEventListener('mouseenter', function () {
    
    
        //     console.log(11);

        // })
        father.addEventListener('mouseleave', function () {
    
    
            console.log(11);

        })

猜你喜欢

转载自blog.csdn.net/chuan0106/article/details/124585268