Js实现div跟着鼠标移动的代码教程
程序员文章站
2023-11-14 16:21:58
js实现p跟着鼠标移动的代码教程
html>
js实现p跟着鼠标移动的代码教程
html> <html lang="en"> <head> <meta charset="utf-8"> <title>title> <style> *{ margin: 0; padding: 0; } #p1{ width: 0; height: 0; border-left: 10px solid green; border-right: 10px solid red; border-top: 10px solid yellow; border-bottom: 10px solid blue; border-radius: 100px; position: absolute; left: 0; top: 0; } style> <script> document.onmousemove=function(e){ var p=document.getelementbyid("p1"); p.style.left=e.clientx+"px"; p.style.top=e.clienty+"px"; } script> head> <body> <p id="p1">p> body> html>