Search code examples
javascriptdelayonload

triggering multiple timed JavaScript functions onload


I've got a beautifully cheesy fireworks animation that I trigger onload using this code

<body onload="createFirework(50,1500,15,1,1,100,50,50,false,false); "> 

I want to trigger 3 instances of the fireworks 1 second apart onload, however I don't know the best method to achieve this.

Many thanks, Mike


Solution

  • To create a separate function where you will call createFirework 3 times. So you can play with params for each firework

    <script>
      function createMyFirework(){
        createFirework(50,1500,15,1,1,100,50,50,false,false);
        createFirework(50,1500,15,1,1,100,50,50,false,false);
        createFirework(50,1500,15,1,1,100,50,50,false,false);
      }
    </script>
    
    <body onload="createMyFirework(); ">