Click to See Complete Forum and Search --> : drag and drop problem


Carter
07-11-2003, 07:42 PM
I'm trying to adapt this drag and drop script to a card game.
MouseClickUp leaves the card in last position, my idea is to have it return to left:600 top:170(onmouseup) but the task eludes me because I don't totally understand the script.
Would like to know how and why.
Thanks

<div id='1' style='position:absolute;left:600;top:170;'>
<img src='_cardback.jpg' name='1'>
</div>
<div id='1' style='position:absolute;left:600;top:170;'>
<img src='_cardback.jpg' name='2'>
</div>
<script language="javascript">
Wholething = (document.all) ? 0 : 1;
var objectone;
var objecttwo;
function MouseMovement(e)
{
if (objectone) {
if (Wholething) {
objectone.moveTo((e.pageX-X), (e.pageY-Y));
}
else {
objectone.pixelLeft = event.clientX-X + document.body.scrollLeft;
objectone.pixelTop = event.clientY-Y + document.body.scrollTop;
return false;
}
}
}
function MouseClickDown(e)
{
if (Wholething) {
objectone = document.layers[e.target.name];
X=e.x;
Y=e.y;
return false;
}
else {
objectone = event.srcElement.parentElement.style;
X=event.offsetX;
Y=event.offsetY;
}
}
function MouseClickUp()
{
objectone=null;
}
document.onmouseup = MouseClickUp;
document.onmousedown = MouseClickDown;
document.onmousemove = MouseMovement;

micjohnson
07-11-2003, 09:44 PM
<div id='1' style='position:absolute;left:600;top:170;'>
<img src='_cardback.jpg' name='1'>
</div>
<div id='1' style='position:absolute;left:600;top:170;'>
<img src='_cardback.jpg' name='2'>
</div>
you cant have two "divs" with the same id
also try throwing a </script> at the end

also shouldnt this be more at the begining? arent they variables?
document.onmouseup = MouseClickUp;
document.onmousedown = MouseClickDown;
document.onmousemove = MouseMovement;

Carter
07-12-2003, 01:01 AM
The code as it is works fine with the script tags. MouseClickUp leaves the image in a new position. On MouseClickUp I would like the image to return to original pos.

micjohnson
07-12-2003, 01:03 AM
document.onmouseup = MouseClickUp();
document.onmousedown = MouseClickDown();
document.onmousemove = MouseMovement();