You need to capture the mouse event, then set the element's left and top properties to the x and y of the mouse event, respectively.
HTML Code:
<html>
<head>
<title>
Drag
</title>
<style type="text/css">
#draggable {
position: absolute;
top: 0;
left: 0;
}
</style>
<script type="text/javascript">
<!--
drag = false;
function mdHandle() {
drag = !drag;
}
function mvHandle(evt) {
if(drag) {
obj = document.getElementById("draggable");
obj.style.top = (evt.pageY - 88) + "px";
obj.style.left = (evt.pageX - 88) + "px";
}
}
//-->
</script>
</head>
<body onmousemove="mvHandle(event);">
<div id="draggable" onmousedown="mdHandle();">
<img src="http://www.grand-illusions.com/images/moonphoto.jpg"/>
</div>
</body>
</html>
Adjust as needed.
Bookmarks