Search code examples
javascripteventstimed

timed events to loop forever


I have this code which is executed on page load:

<script type="text/javascript">
function timedEvent1()
{
  setTimeout("ShowObjectWithEffect('wb_TextArt2', 1, 'dropup', 500)",0);
  setTimeout("ShowObjectWithEffect('wb_TextArt2', 0, 'dropdown', 500)",3000);
  setTimeout("ShowObjectWithEffect('wb_TextArt3', 1, 'dropup', 500)",3000);
  setTimeout("ShowObjectWithEffect('wb_TextArt3', 0, 'dropdown', 500)",6000);
  setTimeout("ShowObjectWithEffect('wb_TextArt4', 1, 'dropup', 500)",6000);
  setTimeout("ShowObjectWithEffect('wb_TextArt4', 0, 'dropdown', 500)",9000);
  setTimeout("ShowObjectWithEffect('wb_TextArt5', 1, 'dropup', 500)",9000);
  setTimeout("ShowObjectWithEffect('wb_TextArt5', 0, 'dropdown', 500)",12000);
  setTimeout("ShowObjectWithEffect('wb_TextArt6', 1, 'dropup', 500)",12000);
  setTimeout("ShowObjectWithEffect('wb_TextArt6', 0, 'dropdown', 500)",15000);
}
</script>

How can I loop this set of events forever? I read about the "setInterval" function but I cannot seem to implement it correctly in the above code.

Thanks.


Solution

  • Have you tried this?

    function timedEvent1() {
        setTimeout("ShowObjectWithEffect('wb_TextArt2', 1, 'dropup', 500)", 0);
        setTimeout("ShowObjectWithEffect('wb_TextArt2', 0, 'dropdown', 500)", 3000);
        setTimeout("ShowObjectWithEffect('wb_TextArt3', 1, 'dropup', 500)", 3000);
        setTimeout("ShowObjectWithEffect('wb_TextArt3', 0, 'dropdown', 500)", 6000);
        setTimeout("ShowObjectWithEffect('wb_TextArt4', 1, 'dropup', 500)", 6000);
        setTimeout("ShowObjectWithEffect('wb_TextArt4', 0, 'dropdown', 500)", 9000);
        setTimeout("ShowObjectWithEffect('wb_TextArt5', 1, 'dropup', 500)", 9000);
        setTimeout("ShowObjectWithEffect('wb_TextArt5', 0, 'dropdown', 500)", 12000);
        setTimeout("ShowObjectWithEffect('wb_TextArt6', 1, 'dropup', 500)", 12000);
        setTimeout("ShowObjectWithEffect('wb_TextArt6', 0, 'dropdown', 500)", 15000);
        setTimeout(timedEvent1, 18000);
    }