How to make alternate background images animation for a web page

This code can be used to make fade animation alternatively on background images for a web page . 
 
Suppose there are two images and we want to change them in background with set interval of time.
Then we will create two divs and in the script we will use fadeToggle for each div in setInterval function. Just like as follows: 
 
CODE: 
  1. <div id="bg1">  
  2.     <img src="img/abhi.jpg"/>  
  3. </div>  
  4. <div id="bg2" >  
  5.     <img src="img/abhi2.jpg"/>  
  6. </div>  
  7. <script type="text/javascript">  
  8. $(document).ready(function()  
  9. {  
  10.     $('#bg2').fadeToggle(8000);  
  11.     function loopBackground()  
  12. {  
  13. setInterval(function()  
  14. {  
  15.     $('#bg1').fadeToggle(8000);  
  16.     $('#bg2').fadeToggle(8000);  
  17. },8000);  
  18. }  
  19. loopBackground();  
  20. });  
  21. </script>  
Ebook Download
View all
Learn
View all