You could implement this by using Javascript to toggle classes with a delay - that would allow older browsers to still have the images change. As we are looking forward though, we'll use CSS keyframes.
Each image is visible for 9 seconds before fading to the other one.
Everything's the same as Demo 1, but I've added this to the CSS and removed the hover selector
@keyframes cf3FadeInOut {
0% {
opacity:1;
}
45% {
opacity:1;
}
55% {
opacity:0;
}
100% {
opacity:0;
}
}
#cf3 img.top {
animation-name: cf3FadeInOut;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
animation-duration: 10s;
animation-direction: alternate;
}
To make sense of that, I've defined 4 keyframes, specified that whatever has this animation attached will be opaque for the first 45%, then transparent for the last 45%. The animation will repeat forever, will last 10 seconds, and will run forward then backwards. In other words, image 1 will be visible for 4.5 seconds, followed by a 1 second fade, followed by 4.5 seconds of image 2 being visible. Then it will reverse, meaning that image 1 and 2 will both be visible for 9 (4.5 x 2) seconds each time.
Staggering the animations can result in a multiple image fader.
This time I've created an animation that goes from 0 to 1 opacity, then staggered the animations so only one is visible at once. It's not great, but it is maybe a start. Any suggestions on how to make this better would be gladly received!
#cf4a img:nth-of-type(1) {
animation-delay: 0;
}
#cf4a img:nth-of-type(2) {
animation-delay: 2s;
}
#cf4a img:nth-of-type(3) {
animation-delay: 4s;
}
#cf4a img:nth-of-type(4) {
animation-delay: 6s;
}
Please add any questions/corrections/extra info below. Please be courteous to other users.
blog comments powered by Disqus