js 鼠标跟随

 div { position: absolute;width: 10px;height: 10px;background: #f00;}

<script type="text/javascript">
    for (var i = 0; i < 10; i++) {
      var oDiv = document.createElement("div");
      document.body.appendChild(oDiv);
    }
    var aDiv = document.querySelectorAll("div");
    document.onmousemove = function (e) {
      var evt = e || event;
      var x = evt.clientX;
      var y = evt.clientY;
      aDiv[0].style.left = x + "px";
      aDiv[0].style.top = y + "px";
      for (var i = aDiv.length - 1; i >= 1; i--) {
        aDiv[i].style.left = aDiv[i - 1].style.left;
        aDiv[i].style.top = aDiv[i - 1].style.top;
      }
    }
  </script>

 

上一篇:Websocket————错误总结


下一篇:小说网站禁止复制黏贴功能