<div class="htmlarea"> <textarea id="runcode17943"> <title></title> <style type="text/css"> #level{ border: 1px solid #ccc; background: #CCFFCC; width:100px;height:30px; position:absolute; } </style> <div id="level"> </div> 콘텐츠 </textarea> <br><input onclick="runEx('runcode17943')" type="button" value="运行代码"><input onclick="doCopy('runcode17943')" type="button" value="复制代码"> <input onclick="doSave(runcode17943)" type="button" value="保存代码"> <a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">[Ctrl A 모두 선택 참고: </a>외부 J를 도입해야 하는 경우 실행하려면 새로 고쳐야 합니다 </div>]<script type="text/javascript"> function addEvent(elm, evType, fn, useCapture) { if (elm.addEventListener){ elm.addEventListener(evType, fn, useCapture); return true; } else if (elm.attachEvent){ var r = elm.attachEvent("on"+evType, fn); return r; } else { alert("Handler could not be removed"); } } var x,y,t; function doit(evt){ var event=evt||window.event; var level=document.getElementById("level"); /*如果是第一次调用该函数level.style.left和level.style.top都为空,所以要初始化*/ if(!level.style.left)level.style.left="1px"; if(!level.style.top)level.style.top="1px"; //用setTimeout函数调用该函数时event对象不存在,只有移动事件触发时event才存在 if(event){x=(event.x||event.pageX)}; if(event){y=(event.y||event.pageY)}; var theLeft=parseInt(level.style.left); var theTop=parseInt(level.style.top); if(x!=theLeft){ if(theLeft<x){ level.style.left=(theLeft+1)+"px"; }else{ level.style.left=(theLeft-1)+"px"; } } if(theTop!=y){ if(theTop<y){ level.style.top=(theTop+1)+"px"; }else{ level.style.top=(theTop-1)+"px"; } } if(x!=theLeft||y!=theTop) setTimeout("doit()",100); } addEvent(document,"mousemove",doit); </script>