JS:鼠标移入移出事件监听

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>鼠标移入移出显示效果</title>
    <style>
    #div1 {
      width: 150px;
      height:50px;
      background: #fffccc;
      border:1px solid #999;
      display: none;
    }
    #div2{
      width: 200px;
      height:200px;
      background: red;
    }
    </style>
  </head>
  <body>
    <input type="checkbox" onmouseover="document.getElementById('div1').style.display='block';"
     onmouseout="document.getElementById('div1').style.display='none';">
    <div id="div2" onmousemove="over()" onmouseout="out()"></div>
  </body>
   <script type="text/javascript">
   function over(){
     var obj=document.getElementById("div2");
     obj.style.width="400px";
     obj.style.height="400px";
     obj.style.background="green";
   }
   function out(){
     var obj=document.getElementById("div2");
     obj.style.width="200px";
     obj.style.height="200px";
     obj.style.background="red";
   }
   </script>
</html>

猜你喜欢

转载自blog.csdn.net/qq_42192693/article/details/82426617