Hi there.. I am trying to change the css background image on the <html> tag. What I need exactly is this, switch between 3 background images with a 100 delay, then wait another 5000 delay, and start again, and it will keep going like this. Any help please? Thanks a lot.
I'm new at javascript.. didn't understand any of that, sorry :/ I have found this code, and it continuously switches betweed the two backgrounds, is there a way to add a third and then pause before restarting? Thanks. var rotate = false; function setbackground(){ window.setTimeout( "setbackground()", 100); newImage = rotate ? 'url(portfolio-back.jpg)' : 'url(portfolio-back2.jpg)'; rotate = !rotate; document.body.style.backgroundImage = newImage; } setbackground(); Code (JavaScript):
try something like this https://jsfiddle.net/bbm5zeuz/ var rotate = 0; var sampleImages = [ 'https://cdnjs.cloudflare.com/ajax/libs/fatcow-icons/20130425/FatCow_Icons16x16/angel.png', 'https://cdnjs.cloudflare.com/ajax/libs/fatcow-icons/20130425/FatCow_Icons16x16/anchor.png', 'https://cdnjs.cloudflare.com/ajax/libs/fatcow-icons/20130425/FatCow_Icons16x16/arch_linux.png' ] setBackground(); function setBackground() { rotate = rotate+1; if (rotate >= sampleImages.length) { rotate = 0; } var testme = document.getElementById('testme'); testme.style.backgroundImage = "url("+sampleImages[rotate]+")"; setTimeout(setBackground, 800); } Code (markup): If you want to fiddle around with the delay then just put them into an array too and use this for the timeout setTimeout(setBackground, timeouts[rotate]); Code (markup):