一串div 跟随鼠标移动

2017-10-11  本文已影响0人  发光驴子
  <!DOCTYPE html>
  <html lang="en">
  <head>
      <meta charset="UTF-8">
      <title>Title</title>
  </head>
  <script>
      window.onload=function () {
          var oDiv=document.getElementsByTagName('div');
          document.onmousemove=function (ev) {
              var oEvent=ev||event;
              oDiv[0].style.left=oEvent.clientX+"px";
              oDiv[0].style.top=oEvent.clientY+"px";
              for(var i=oDiv.length-1; i>0;i--){
                  oDiv[i].style.left=oDiv[i-1].style.left;
                  oDiv[i].style.top=oDiv[i-1].style.top;
              }

          }
      }
  </script>
  <style>
div{
    width:100px;
    height:150px;
    background: red;
    position: absolute;
      }
  </style>
  <body >

  <div></div>
  <div></div>
  <div></div>
  <div></div>
   <div></div>
  <div></div>
  <div></div>
  <div></div>
  </body>
  </html>
上一篇 下一篇

猜你喜欢

热点阅读