<div class="htmlarea"> <textarea id="runcode46270"> <script type="text/javascript"> var ie=document.all; var nn6=document.getElementById&&!document.all; var isdrag=false; var x,y; var dobj; function movemouse(e) { if (isdrag) { dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x; dobj.style.top = nn6 ? ty + e.clientY - y : ty + event.clientY - y; return false; } } function selectmouse(e) { var fobj = nn6 ? e.target : event.srcElement; var topelement = nn6 ? "HTML" : "BODY"; while (fobj.tagName != topelement && fobj.className != "dragme") { fobj = nn6 ? fobj.parentNode : fobj.parentElement; } if (fobj.className=="dragme") { isdrag = true; dobj = fobj; tx = parseInt(dobj.style.left+0); ty = parseInt(dobj.style.top+0); x = nn6 ? e.clientX : event.clientX; y = nn6 ? e.clientY : event.clientY; document.onmousemove=movemouse; return false; } } document.onmousedown=selectmouse; document.onmouseup=new Function("isdrag=false"); </script> <div align="center"> <img src="http://www.jb51.net/images/logo.gif" style="max-width:90%" style="max-width:90%" style="max-width:90%" class="dragme" alt="代码短小的js div层拖动实现代码[兼容IE与Firefox]_javascript技巧" > </div> </textarea><br><input onclick="runEx('runcode46270')" type="button" value="运行代码"> <input onclick="doCopy('runcode46270')" type="button" value="复制代码"> <input onclick="doSave(runcode46270)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>