Hey i want to fade in a new background image let´s say every 60 seconds. I´ve set the background image like this:
body {background-image: url(background.jpg);}
Now i want to change it, so after 60seconds it changes to background2.jpg, then after 60 seconds to background3.jpg and so on..
I´ve found a lot of stuff without changing it in the body but just as an image... any quick solutions?
Thank you!
});
You can use the
setInterval
method and switch between classes defined in your CSS which have different background-images:Fiddle
This example uses an interval of
1000
which is one second. You can change this value for whatever period of time you're looking for.UPDATE
Noticed your question asked for a fade so I added a CSS3 property on body:
The fiddle has been updated.
Building on Deryck's answer...
If jQuery Color does not function properly (which it sometimes does), you can use
fadeIn()
andfadeOut()
instead:Re-UPDATE of the UPDATE:
Even NEWER Fiddle (without arguments.callee)
Changes:
BIG UPDATE
Took the meat of this code from this previous answer and added some bling (using my site background stash lol)
original fiddle :)
NEW Super Fiddle
Javascript:
CSS:
Building on the answer from Dan-Nolan (formerly user506980), you can also assign the backgrounds to an array and then call each background from the array with a counter
jsFiddle Demo
Further, you can assign the setInterval function to a variable, and then use that variable later to stop the repeats.
Since I built upon Dan-Nolan's answer, please upvote his answer if you upvote this one. And I see that Deryck has added his, and it is also correct. Upvote.
Each 12 seconds an image is changed in presentacion container; it can be body tag
HTML
JS
delay(11000) + setTimeout(1000) = 12 sec transition duration = 300 + 300 = 600 msec
CSS