Last updated on May 10th, 2022 at 05:19 pm

In this tutorial we will create a simple slideshow using jQuery. For that we need to first define a div with id as slideshow. Also have option to control the speed of the slideshow.

<div id="slideshow">
    <img src="img/img1.jpg" alt="" class="active" />
    <img src="img/img2.jpg" alt="" />
    <img src="img/img3.jpg" alt="" />

Next CSS to position the images on top of each other and bring the active image to the top level

#slideshow {

#slideshow IMG {

#slideshow {

#slideshow IMG.last-active {

Now we have the structure. Implementing the slideshow comes next and it can be accomplished using jQuery

function slideSwitch() {
    var $active = $('#slideshow');

    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');

    var $next =  $ ? $
        : $('#slideshow IMG:first');


    $next.css({opacity: 0.0})
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');

$(function() {
    setInterval( "slideSwitch()", 5000 );

You might also be interested in Image slideshow with navigation and description

You are free to increase or decrease the speed of the slideshow using , change 5000 to some other value of your choice to control the speed.

setInterval( "slideSwitch()", 5000 );

Note you can add the jQuery section using

<script src="" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>


Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *