I found this simple Slideshow on the Internet, but the problem is that it doesn't repeat itself.
What I mean, is that it goes from 1 to 2, but doesn't go back to 1. What do I have to modify in the jQuery? Thanks, this is my first post.
JavaScript Code:
function slideSwitch() {
var mylenght = 5;
var $active = $('#slideshow IMG.active');
if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
if ($active.length == mylenght) $active = $("#slideshow IMG:first")
// use this to pull the images in the order they appear in the markup
var $next = $active.next().length ? $active.next()
: $('#slideshow IMG:first');
// uncomment the 3 lines below to pull the images in random order
// var $sibs = $active.siblings();
// var rndNum = Math.floor(Math.random() * $sibs.length );
// var $next = $( $sibs[ rndNum ] );
$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 );
});
Try this,
function slideSwitch() {
var mylenght = 4;
var $active = $('#slideshow IMG.active');
if ($('#slideshow IMG').index($active) == mylenght - 1)
$next = $("#slideshow IMG:first")
else
$next = $active.next();
$next.addClass('active').css({opacity: 0.0}).animate({opacity: 1.0}, 1000);
$active.removeClass('active').css({opacity: 1.0}).animate({opacity: 0}, 1000);
}
Have a look here http://jsfiddle.net/iamrmin/K62DX/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.