The Mouse up and Mouse Down events can also be captured.
When the mouse down event occurs and the user moves the mouse,
the image can follow the mouse. When mouse down occurs,
the drag is ended.
var xLoc, yLoc, drg=false;
document.onmousemove = mouseMove;
document.onmouseup = mouseUp;
function mouseDown(e)
{
if (window.event)
e=window.event
xLoc=e.clientX - document.getElementById("tee").offsetLeft;
yLoc=e.clientY - document.getElementById("tee").offsetTop;
drg=true;
}
function mouseUp(e)
{
drg=false;
}
function mouseMove()
{
var MovedX, MovedY;
if (!drg)
return;
if (window.event)
e= window.event;
MovedX=e.clientX - xLoc;
MovedY=e.clientY - yLoc;
document.getElementById("tee").style.left=MovedX;
document.getElementById("tee").style.top=MovedY;
return false;
}
Dragging Images in IE (not Firefox)