115S站长学院 TIY
编辑您的代码:
<html> <head> <style> img { position:relative; } </style> <script type="text/javascript"> mouseover=true function coordinates() { if (!moveMe) { return } if (event.srcElement.id=="moveMe") { mouseover=true pleft=document.getElementById('moveMe').style.pixelLeft ptop=document.getElementById('moveMe').style.pixelTop xcoor=event.clientX ycoor=event.clientY document.onmousemove=moveImage } } function moveImage() { if (mouseover&&event.button==1) { document.getElementById('moveMe').style.pixelLeft=pleft+event.clientX-xcoor document.getElementById('moveMe').style.pixelTop=ptop+event.clientY-ycoor return false } } function mouseup() { mouseover=false } document.onmousedown=coordinates document.onmouseup=mouseup </script> </head> <body> <img id="moveMe" src="../i/eg_smile.gif" tppabs="http://zz.115s.com/i/eg_smile.gif" /><br /> <b>请拖动这幅图像。</b> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?72e1eb95f3722bd737488ab37f422304"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </body> </html>
查看结果: