A carousel is an animated image slideshow that plays by itself and is used to show off news features or products. On this page I will take a basic model and add some improvements, to give it better looks and more function.
The basic slideshow
The basic carousel structure found at w3schools.com is very similar to the javascript lightbox (see my Lightbox Q page), but without any thumbnails to click on (although you could have thumbs underneath, instead of dots) and no fullscreen user immersion, so it fits into the page design.
Here are the parts, the html layout first...
View code
And the js...
View code
The method here is ultra simple, using js to add the 'display: block' value inline to the new slide, and just before that, all slides are killed (the line: slides[i].style.display = "none"; ) or set with no display.
An index is created at the first line, beginning at 0, and the function increments the index no. each time, by 'slideIndex++'. So on te initial run, the index no. becomes 1, An array is built of the slide divs 'mySlides' and as arrays start at 0, each slide in the array is called with the index no. minus 1 to call the correct slide (slide 1 is array 0).
In the CSS, the class 'mySlides' needs 'display: none', and the 'fade-in' class is like so...
View code
You can also use a cubic-bezier instead of 'ease-out'
View code
So what you get is the new slide fades in over a blank div area, the carousel kind of blinking as it does so (previous slide is killed without any transition out). There's no cross-fade of old and new slides.