mouseenter & mouseover 的区别
- mouseover 鼠标经过自身盒子会触发 经过子盒子还会触发(会冒泡)
- mouseenter只会经过自身盒子触发(不会冒泡)
实例
<!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>mouseenter和mouseover的区别</title> <style> .father{ width: 200px; height: 200px; background-color: lightblue; } .son{ width: 100px; height: 100px; background-color: pink; } </style> </head> <body> <div class="father"> <div class="son"></div> </div> <script> var father = document.querySelector('.father') var son = document.querySelector('.son') //会冒泡 father.addEventListener('mouseover',function(){ console.log(1); }) // 不会冒泡 /* father.addEventListener('mouseenter',function(){ console.log(1); }) */ </script> </body> </html>
不积跬步无以至千里 不积小流无以成江海