10_DOM_鼠标滑动事件.html 810 B

1234567891011121314151617181920212223242526272829
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. .box{
  9. width: 200px;
  10. height: 200px;
  11. background-color: red;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <div class="box"></div>
  17. <script>
  18. var oBox = document.getElementsByClassName("box")[0];
  19. // 鼠标移入事件 mouseover 当鼠标移入某一个元素的时候触发
  20. oBox.onmouseover = function(){
  21. console.log("鼠标移入了");
  22. }
  23. // 鼠标移出事件 mouseout 当鼠标移出某一个元素的时候触发
  24. oBox.onmouseout = function(){
  25. console.log("鼠标移出了");
  26. }
  27. </script>
  28. </body>
  29. </html>