-
Javascript movement
I wrote the following code to move text around the screen in javascript and i can't figure out what is wrong with it... can someone help?
<HTML>
<HEAD>
<TITLE>
Movement
</TITLE>
<script language = "javascript">
firstTime = true;
function moveIt()
{
if (firstTime)
{
document.all.mover.style.pixelTop = 5
firstTime = false
}
document.all.mover.style.pixelTop += 5
setTimeout("moveIt()", 20)
}
</script>
</HEAD>
<BODY onLoad = "MoveIt()">
<DIV ID = "mover" STYLE = "POSITION: ABSOLUTE; LEFT: 5PX; TOP: 5PX;">
<P>
Hello, World!!!
</P>
</DIV>
</BODY>
</HTML>
Thanks in advance
-
kryptonite0110, surprisingly enough, function name is case sensitive (I just knew it myself *).
So try to change all reference to "MoveIt()" to the same case and reload the page. Note that you need to tell the browser when to stop, since your javascript will move the "Hello, World" text down continuously.
*) What I did was loading the page in Mozilla and type javascript: in the location bar, which displayed "Error: MoveIt is not defined in the JavaScript console. Then I changed the all "MoveIt()" to the same case, and reload the page. It still didn't move the text and I expected that, since the HTML doc is designed to run ONLY in IE (it uses document.all - IE proprietary). Mozilla's JavaScript console also confirmed that. But now it's safe to load it in IE and it works properly.
BTW, does anybody know if there is similar JavaScript console in IE and how to open it?
Peace always,
<jdenny>