Tryit Editor v1.4

<html> <head> <style> img { position:absolute; } </style> <script type="text/javascript"> document.onmousedown=coordinates; document.onmouseup=mouseup; function coordinates(e) { if (e == null) { e = window.event;} var sender = (typeof( window.event ) != "undefined" ) ? e.srcElement : e.target; if (sender.id=="moveMe") { mouseover=true; pleft=parseInt(movMeId.style.left); ptop=parseInt(movMeId.style.top); xcoor=e.clientX; ycoor=e.clientY; document.onmousemove=moveImage; return false; } else { return false; } } function moveImage(e) { if (e == null) { e = window.event;} movMeId.style.left=pleft+e.clientX-xcoor+"px"; movMeId.style.top=ptop+e.clientY-ycoor+"px"; return false; } function mouseup(e) { document.onmousemove=null; } </script> </head> <body> <img id="moveMe" src="smiley.gif" width="32" height="32" /> <p>Drag and drop the image</p> <script type="text/javascript"> //The movable image movMeId=document.getElementById("moveMe"); //image starting location movMeId.style.top="75px"; movMeId.style.left="75px"; </script> </body> </html> | Your Result:
Edit the code above and click to see the result. | W3Schools.com - Try it yourself