I have the following code
<script language="JavaScript" type="text/javascript"><!-
-
gotInitMousePos = false;
initDIV = "";
initMouseX = 0;
initMouseY = 0;
initDIVX = 0;
initDIVY = 0;
function getX(e)
{
e = e || window.event; // So if I pass e in how come I need to do this if client is Konquorer/IE???
return e.clientX; // + document.body.scrollLeft;
}
function getY(e)
{
e = e || window.event; // So if I pass e in how come I need to do this???
return e.clientY; // + document.body.scrollTop;
}
function initMoveDIV(DIVname)
{
initDIV = DIVname;
gotInitMousePos = false;
initDIVX = parseInt(document.getEleme
ntById(DIV
name).styl
e.left);
initDIVY = parseInt(document.getEleme
ntById(DIV
name).styl
e.top);
document.onmouseup = stopMoveDIV;
document.onmousemove = moveIt;
if(event) event.returnValue = false;
}
function stopMoveDIV(e)
{
e = e || window.event;
document.onmousemove = null;
gotInitMousePos = false;
e.returnValue = false;
}
function moveIt(e)
{
e = e || window.event;
if(!gotInitMousePos)
{
initMouseX = getX(e);
initMouseY = getY(e);
gotInitMousePos = true;
}
moveDIV(initDIV, initDIVX - initMouseX + getX(e), initDIVY - initMouseY + getY(e));
e.returnValue = false;
}
function moveDIV(DIVname, x_pos, y_pos)
{
document.getElementById(DI
Vname).sty
le.left = x_pos + "px";
document.getElementById(DI
Vname).sty
le.top = y_pos + "px";
}
//......
--></script>
The implementation is at
http://www.latimer.uklinux.net/fridge/fridge.php if you need to see what it it supposed to do.
However, with Mozilla, if you move the mouse too quickly the processing is going wrong, but move it slow and all is fine. What happens is DIV doesn't move properly and onmouseup event isn't captured.
Similar behaviour happens in Konquorer/IE if I remove the event.returnValue = false from the initMoveDIV function, so I think it might be a similar issue, however I don't actually know why I need this bit of code anyway.
Help in this matter will be well appreciated.
Start Free Trial