<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> *{ margin:0; padding:0; } div{ width: 100px; height: 100px; background: red; position: absolute; } </style> </head> <body> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> <script> document.onmousemove=function fn(ev) { var event=window.event||ev; var oDiv=document.getElementsByTagName("div"); for(x=0;x<oDiv.length;x++){ oDiv[x].style.transition=(x*0.5)+"s"; oDiv[x].style.left=event.clientX+"px"; oDiv[x].style.top=event.clientY+"px"; } } </script> </body> </html>
js实现盒子跟着鼠标移动效果
最新推荐文章于 2023-12-12 10:58:38 发布