[Javascript] Timed demo doesn't work as expected, why?

Peter Brunone peter at brunone.com
Sun Mar 30 14:00:01 CDT 2008


From: tedd   tedd at sperling.com 

> How can I get it to be sequential?

This is what I was talking about when I mentioned a function that calls itself recursively with a setTimeout and then checks to see if the next element exists.  If the element does exist, the function would hide it, up the counter, and call itself again with another setTimeout.  When it finds that there is no current element to hide/show, it stops calling itself and you're done.

The difference with this method is that you use only the non-integer part of the ID to call the function, e.g. timedLayer("hide").  I haven't tested this so it may have a bug or two, but hopefully you get the idea.

var iLayer = 0;

function HideTimedLayer(id) {
   if(iLayer > 0) && document.getElementById(id + iLayer)) {
      document.getElementById(id).style.display = "none";
      setTimeout("HideTimedLayer(\"" + id + "\")", 1000);
      }
   else if(iLayer == 0) { iLayer++; }
   }

HTH,

Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20080330/9d5d0058/attachment.htm>


More information about the Javascript mailing list