<img id="pic" src="images/beetle.gif" style="position:absolute;left:100px;top:100px;"> <script type="text/javascript"> function move(){ var key = event.keyCode; var x = parseInt(pic.style.left); var y = parseInt(pic.style.top); var step = 10; if (key == 37) pic.style.left = x - step + "px"; if (key == 38) pic.style.top = y - step + "px"; if (key == 39) pic.style.left = x + step + "px"; if (key == 40) pic.style.top = y + step + "px";
<img src="images/beetle.gif" style="position:absolute;left:0px;top:0px;" onMouseDown="dragImage(this)"> <script type="text/javascript"> var down = false; var x,y,imgID;
function dragImage(obj){ imgID = obj; x = event.x - parseInt(imgID.style.left); y = event.y - parseInt(imgID.style.top);