Add wait or sleep command with setInterval() method - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window setInterval

Description

Add wait or sleep command with setInterval() method

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){// ww w. j  a va 2s.  c  o  m
var colors = ['red', 'green', 'blue']
var count = 0;
setInterval(function () {
  document.body.style.backgroundColor = colors[count];
  count ++ ;
  if(count >= colors.length){
      count = 0;
  }
},1000)
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials