Created
November 29, 2012 11:08
-
-
Save adibhanna/4168248 to your computer and use it in GitHub Desktop.
jquery: multiple background
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(window).load(function(){ | |
var images = ['blaa.jpg','sdsd.jpg']; | |
var i = 0; | |
function changeBackground() { | |
jQuery('#absolute-c').css('background-image', function() { | |
if (i >= images.length) { | |
i=0; | |
} | |
return 'url(' + images[i++] + ')'; | |
}); | |
} | |
// Call it on the first time | |
changeBackground(); | |
// Set an interval to continue | |
setInterval(changeBackground, 3000); | |
}); | |
//....................................................... | |
jQuery(window).load(function(){ | |
var images = ['picture1.jpg','picture2.jpg']; | |
var i = 0; | |
var timeoutVar; | |
function changeBackground() { | |
clearTimeout(timeoutVar); // just to be sure it will run only once at a time | |
jQuery('#absolute-c').css('background-image', function() { | |
if (i >= images.length) { | |
i=0; | |
} | |
return 'url(' + images[i++] + ')'; | |
}); | |
// call the setTimeout every time to repeat the function | |
timeoutVar = setTimeout(changeBackground, 3000); | |
} | |
// Call it on the first time and it will repeat | |
changeBackground(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment