Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(window).load(function(){
  2.     var images = ['blaa.jpg','sdsd.jpg'];
  3.     var i = 0;
  4.     var timeoutVar;
  5.  
  6.     function changeBackground() {
  7.         clearTimeout(timeoutVar); // just to be sure it will run only once at a time
  8.  
  9.         jQuery('#absolute-c').css('background-image', function() {
  10.             if (i >= images.length) {
  11.                 i=0;
  12.             }
  13.             return 'url(' + images[i++] + ')';      
  14.         });
  15.  
  16.         // call the setTimeout every time to repeat the function
  17.         timeoutVar = setTimeout(changeBackground, 3000);
  18.     }
  19.  
  20.     // Call it on the first time and it will repeat
  21.     changeBackground();        
  22. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement