facebook twitter youtube
in Jquery - 29 Dec, 2009, This Tutorial Has Been Viewed 136,325 Times.
by admin - no comments
Slideshow using jquery
VN:F [1.9.22_1171]
Rating: 6.3/10 (3 votes cast)

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.22_1171]
Rating: 6.3/10 (3 votes cast)
Slideshow using jquery, 6.3 out of 10 based on 3 ratings

Incoming search terms:




coded by nessus

Leave a Reply

Close
Please support the site
By clicking any of these buttons you help our site to get better