我在互联网上发现了这个简单的幻灯片,但问题在于它并没有重演。
我的意思是,它是从1到2,但是没有回到1.我需要在jQuery中修改什么?谢谢,这是我的第一篇文章。
JavaScript代码:
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 );
});
答案 0 :(得分:0)
试试这个,
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);
}