Pythondev
10-31-2006, 10:19 PM
I want to have a small div on my page which can be moved around using the keys on the keyboard.
So if you press up the div moves up 5px. Down it moves down 5px. Left it moves left 5px. Right it moves right 5px.
Ok, I have been able to get it working fine in IE but cant get it to work in Firefox...
This is what I have...
<HTML>
<HEAD>
<TITLE>Cursor Mover</TITLE>
<SCRIPT>
function move()
{
ek = window.event.keyCode;
if (ek==37) DIV1.style.posLeft-=5;
if (ek==39) DIV1.style.posLeft+=5;
if (ek==38) DIV1.style.posTop-=5;
if (ek==40) DIV1.style.posTop+=5;
}
</SCRIPT>
</HEAD>
<BODY onkeydown="move();">
<DIV ID="DIV1" style="position:absolute;top:100;left:100;height:20;width:20;background-color:#000000;"></DIV>
</BODY>
</HTML>
How can I get it to work?
Thanks
So if you press up the div moves up 5px. Down it moves down 5px. Left it moves left 5px. Right it moves right 5px.
Ok, I have been able to get it working fine in IE but cant get it to work in Firefox...
This is what I have...
<HTML>
<HEAD>
<TITLE>Cursor Mover</TITLE>
<SCRIPT>
function move()
{
ek = window.event.keyCode;
if (ek==37) DIV1.style.posLeft-=5;
if (ek==39) DIV1.style.posLeft+=5;
if (ek==38) DIV1.style.posTop-=5;
if (ek==40) DIV1.style.posTop+=5;
}
</SCRIPT>
</HEAD>
<BODY onkeydown="move();">
<DIV ID="DIV1" style="position:absolute;top:100;left:100;height:20;width:20;background-color:#000000;"></DIV>
</BODY>
</HTML>
How can I get it to work?
Thanks