首页 > 代码库 > 随鼠标移动
随鼠标移动
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <span id="a" style="position:absolute;border: 1px solid blue"> 跟着我 </span> <script> function a(){ var div = document.getElementById("a"); if (!div) { return; } var intX = window.event.clientX; var intY = window.event.clientY; div.style.left = intX + "px"; div.style.top = intY + "px"; } document.onmousemove = a; </script> </body> </html>
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <span id="a" style="border: 1px solid blue"> 跟着我 </span> <script> function a(){ var div = document.getElementById("a"); div.style.position=‘absolute‘; div.style.left = window.event.clientX+ "px"; div.style.top =window.event.clientY+ "px"; } document.onmousemove = a; </script> </body> </html>
超简单版的跟着鼠标移动
随鼠标移动
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。