Facebook Twitter Reset

This Tutorial Has Been Viewed 3,626 Times.

Slideshow using jquery

Just a simple slideshow using jquery

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

Now let’s use CSS to position the images on top of each other and bring the active image to the top level with z-index:

#slideshow {
    position:relative;
    height:350px;
}

#slideshow IMG {
    position:absolute;
    top:0;
    left:0;
    z-index:8;
}

#slideshow IMG.active {
    z-index:10;
}

#slideshow IMG.last-active {
    z-index:9;
}
The main javascript code

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

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

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

    $active.addClass('last-active');

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

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

The complete code

Download the code here

Note you can get the JS file from http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js

VN:F [1.9.13_1145]
Rating: 6.3/10 (3 votes cast)
VN:F [1.9.13_1145]
Rating: +1 (from 1 vote)
Slideshow using jquery, 6.3 out of 10 based on 3 ratings

Incoming search terms:




You will also be interested in ,

No comments yet.

Leave a Comment

Spam protection by WP Captcha-Free

Affordable Seo PackagesSeo BlogEdu Backlinks
More in Apache, htaccess, PHP, Wordpress Tips (85 of 143 articles)