<div class="codetitle"> <span><a style="CURSOR: pointer" data="9424" class="copybut" id="copybut9424" onclick="doCopy('code9424')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code9424"> <br><script type="text/javascript"> <BR>var ball; <BR>var mouseX = 100; <BR>var mouseY = 100; <BR>var angle = 0; <BR>var radius = 0; <br><br>function draw(){ <BR>ball = document.createElement("span"); <BR>ball.style.position = "absolute"; <BR>ball.style.color = "#FF0000"; <BR>ball.style.zIndex = 999999999; <BR>ball.innerHTML = "●"; <BR>document.body.appendChild(ball); <br><br>ball.style["left"] = mouseX+ "px"; <BR>ball.style["top"] = mouseY+ "px"; <BR>} <BR>function MousePos(e) <BR>{ <BR>e = e || window.event; <BR>var x,y; <BR>if(!document.all){ <BR>x = e.pageX; <BR>y = e.pageY; <BR>} <BR>else{ <BR>x = event.clientX + document.documentElement.scrollLeft; <BR>y = event.clientY + document.documentElement.scrollTop; <BR>} <BR>return {x:x,y:y}; <BR>} <BR>function setXY(e) <BR>{ <BR>e = e || window.event; <BR>var pos = MousePos(e); <BR>mouseX = pos.x; <BR>mouseY = pos.y; <BR>draw(); <BR>} <BR>window.onload = function(){ <BR>document.documentElement.onmousemove = function(e){ <BR>e = e || window.event; <BR>setXY(e); <BR>}; <BR>} <BR></script> <br> </div> <br>效果演示代码:<br><div class="htmlarea"> <textarea id="runcode17710"> <script type="text/javascript"> var ball; var mouseX = 100; var mouseY = 100; var angle = 0; var radius = 0; function draw(){ ball = document.createElement("span"); ball.style.position = "absolute"; ball.style.color = "#FF0000"; ball.style.zIndex = 999999999; ball.innerHTML = "●"; document.body.appendChild(ball); ball.style["left"] = mouseX+ "px"; ball.style["top"] = mouseY+ "px"; } function MousePos(e) { e = e || window.event; var x,y; if(!document.all){ x = e.pageX; y = e.pageY; } else{ x = event.clientX + document.documentElement.scrollLeft; y = event.clientY + document.documentElement.scrollTop; } return {x:x,y:y}; } function setXY(e) { e = e || window.event; var pos = MousePos(e); mouseX = pos.x; mouseY = pos.y; draw(); } window.onload = function(){ document.documentElement.onmousemove = function(e){ e = e || window.event; setXY(e); }; } </script> </textarea><br><input onclick="runEx('runcode17710')" type="button" value="运行代码"> <input onclick="doCopy('runcode17710')" type="button" value="复制代码"> <input onclick="doSave(runcode17710)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div> <br>出处:<a href="http://www.cnblogs.com/airy" target="_blank">http://www.cnblogs.com/airy</a>