Trying to apply and image transition effect to a fixed bg image for a particular div. Currently looks like –
#top-header {
background: #FFF url('/images/image001.jpg') no-repeat top center fixed;
width: 100%;height: 540px;
}
<div id="top-header"></div>
I am aware that CSS3 allows for multiple bg images. Since images are being called through my CSS is it possible to apply javascript to the current div to achieve a fade in/out transition effect?
Thanks!
You can do a lot with JavaScript and CSS however this is a very solved problem with many options for basically showing slideshows. So it might be best to look at one of those. But let’s try it anyway!
HTML:
CSS:
JavaScript:
Demo: jsfiddle
Of course, jQuery already has
fadeInandfadeOutso we can simplify our code by using them:Demo: jsfiddle
We could also use
slideDownandslideUp: jsfiddleSo why not just use this? Well you could however I’m aware of one obvious flaw: we start the slideshow before making sure all the images have been downloaded by the browser. We should fix that. No doubt there are similar issues we may have overlooked but the choice is yours on what to use.