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>
标签:style,鼠标,aDiv,js,跟随,var,div,document,evt 来源: https://www.cnblogs.com/yunyin/p/14770451.html