T
Terry
I am creating some simple animation and as am trying to use setTimeout
to run certain statements every 50 milliseconds.
My animation occurs in this function
function animator(letter)
{
var b,z,p;
var thedivs =
document.getElementById('A').getElementsByTagName('div');
alert("thedivs count = " + thedivs.length);
for (b=0,z=7;b<8;b++,z--)
for (p=0; p <= z; p++)
{
function f()
{
var d;
for (d=0; d < letter[z].length;d++)
{
thedivs[p*6+(letter[z][d])].style.backgroundImage =
"url(images/greendot.gif)";
if (p > 0)
thedivs[(p-1)*6+(letter[z][d])].style.backgroundImage =
"url(images/graydot.gif)";
}
}
setTimeout(f,p*50);
//f();
}
}
If I don't use setTimeout and just call the function directly (i.e.
f()) I get the image of the character 'A' which I want albeit almost
instantaneously.
When I try to use setTimeout the var z is -1 and my code falls apart.
Any suggestions as to how I could fix my problem?
The url to my page is http://theamazing.onlinewebshop.net/newanimate.htm
Thanks,
Terry
to run certain statements every 50 milliseconds.
My animation occurs in this function
function animator(letter)
{
var b,z,p;
var thedivs =
document.getElementById('A').getElementsByTagName('div');
alert("thedivs count = " + thedivs.length);
for (b=0,z=7;b<8;b++,z--)
for (p=0; p <= z; p++)
{
function f()
{
var d;
for (d=0; d < letter[z].length;d++)
{
thedivs[p*6+(letter[z][d])].style.backgroundImage =
"url(images/greendot.gif)";
if (p > 0)
thedivs[(p-1)*6+(letter[z][d])].style.backgroundImage =
"url(images/graydot.gif)";
}
}
setTimeout(f,p*50);
//f();
}
}
If I don't use setTimeout and just call the function directly (i.e.
f()) I get the image of the character 'A' which I want albeit almost
instantaneously.
When I try to use setTimeout the var z is -1 and my code falls apart.
Any suggestions as to how I could fix my problem?
The url to my page is http://theamazing.onlinewebshop.net/newanimate.htm
Thanks,
Terry