標籤:lang set abs style 滑鼠移動 har doc absolute doctype
<!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>
超簡單版的跟著滑鼠移動
隨滑鼠移動