TEST TEST

CSS Looping Fader

iaian7 » code » webcode   John Einselen, 20.05.18 (updated 20.10.18)    

This is based on an example by Jonathan Snook, but has been updated to fade seamlessly between images without cross fading (which reveals the background). This is achieved by animating the z-index while simultaneously delaying the fade out of each layer until the replacing layer is fully visible.

While the animation timeline does depend on a set number of images, it would be possible to set up classes for each variation needed (for example, 4, 5, and 6 image rotations). (fade duration + visible duration) * number of images = total duration which can be used to set up the percentages for the animation timeline. More details can be found in the Jonathan Snook article linked above.

This version uses CSS backgrounds (defined in the HTML by an assumed CMS) instead of <img> tags to provide a more seamless and responsive (depending on your CSS setup) end result. Loading images as backgrounds also prevents them from being selected by accident.

1CSS fader source code

bookmark