It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Endless Loop for setTimeout

Endless Loop for setTimeout

Postby pindi on Fri Aug 28, 2009 8:03 pm

Does anyone know why this function would loop endlessly? If you want the entire code, I can post it. It doesn't loop when I remove the timeout part of the code, so something to do with it looping back to flyIn().

I can maybe add yet another counter that quits the function after one loop, but that seems like a cheat and I'd rather do it correctly.

It works perfectly otherwise (it is supposed to glide some elements of the web page to the left). Like I said I can post everything if necessary.

Code: Select all
function flyIn(evnt){
   //shifts y-axis far to the left
var y = -100;
//choses the label div or class
   if (document.querySelectorAll)
      {
      labels = document.querySelectorAll('div.label');
         }
      else if (document.getElementsByClassName)
         {
      labels = document.getElementsByClassName('label');
      }
//loops through the labels
   if (labels){
         for (var i=1; i <= labels.length; i++)
            {var labelName = "label" + i;
//picks the labels by each Id
               var objFly = document.getElementById(labelName);
//starts a counter
         for (var MoveI=0; MoveI < 200; MoveI++)
               
   {
//sets the position, one pixel at a time
   y = y + 1;
   number_y = y;
   document.getElementById(labelName).style.left = number_y + "px";
   if (number_y < 100) {
        window.setTimeout("flyIn()", 1000);
} alert("got this far");
}
   y=-100;
   }
      }
}
pindi
 
Posts: 1
Joined: Thu Aug 27, 2009 8:50 pm

Who is online

Users browsing this forum: No registered users and 6 guests