<div class="htmlarea"> <textarea id="runcode85378"> <title>跟随鼠标的图片特效</title> <script language="javascript" type="text/javascript"> document.onmousemove = function () { var x = window.event.clientX; var y = window.event.clientY; var divId = document.getElementById("divId"); if (!divId) { return; } divId.style.left = x; divId.style.top = y; } </script> <div id="divId" style="position: absolute; margin-left:20px;"> 这里放的是图片 </div> </textarea><br><input onclick="runEx('runcode85378')" type="button" value="运行代码"> <input onclick="doCopy('runcode85378')" type="button" value="复制代码"> <input onclick="doSave(runcode85378)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div> <br>其实这段代码很简单,也很好理解,只是获取了当前鼠标在屏幕中的位置; 然后再把坐标值赋给图片,或者文字!当然要用到 position:absoluute; 绝对定位!