码迷,mamicode.com
首页 > 其他好文 > 详细

mouseent和mouseover的区别

时间:2020-04-12 20:30:09      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:也会   script   doctype   document   oct   add   body   function   event   

使用mouseover会产生冒泡事件结合onmouseout一起使用

控制台里面的小盒子也会触发大盒子的事件这叫冒泡事件,所以使用mouseover会产生冒泡事件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box1{
            width: 300px;
            height: 300px;
            background-color: brown;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translateY(-50%) translateX(-50%);
        }
        #box2{
            width: 100px;
            height: 100px;
            background-color: blueviolet;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translateY(-50%) translateX(-50%);
        }
    </style>
</head>
<body>
    <div id="box1">
        <div id="box2"></div>  
    </div>
    <script>
        box1.addEventListener("mouseover",function(){
            console.log("被触发");   
        });
    </script>
</body>
</html>

mouseent鼠标经过事件不会产生冒泡事件搭配mouseleave鼠标离开事件使用

鼠标经过小盒子时不会被触发

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box1{
            width: 300px;
            height: 300px;
            background-color: brown;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translateY(-50%) translateX(-50%);
        }
        #box2{
            width: 100px;
            height: 100px;
            background-color: blueviolet;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translateY(-50%) translateX(-50%);
        }
    </style>
</head>
<body>
    <div id="box1">
        <div id="box2"></div>  
    </div>
    <script>
        box1.addEventListener("mouseenter",function(){
            console.log("被触发");   
        });
    </script>
</body>
</html>

 

mouseent和mouseover的区别

标签:也会   script   doctype   document   oct   add   body   function   event   

原文地址:https://www.cnblogs.com/niuyaomin/p/12687120.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!