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 the background with a 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. $('#bg2').fadeToggle(8000);
  10. function loopBackground() {
  11. setInterval(function() {
  12. $('#bg1').fadeToggle(8000);
  13. $('#bg2').fadeToggle(8000);
  14. }, 8000);
  15. }
  16. loopBackground();
  17. });
  18. </script>