您正在使用JQuery幻灯片演示。我的html中的所有图像都是彼此重叠的,我试图让我的代码从最后一张图片开始。但它不起作用,任何想法?
原始代码如下所示:
$(document).ready(function() {
var current = $('#gallery img:first');
//Set the fade in effect for the next image, show class has higher z-index
current.addClass('show').css({
opacity: 0.0
}).animate({
opacity: 1.0
}, 1000);
setInterval('gallery()', 3000);
});
function gallery() {
//if no IMGs have the show class, grab the first image
var current = ($('#gallery img.show') ? $('#gallery img.show') : $('#gallery img:first'));
//Get next image, if it reached the end of the slideshow, rotate it back to the first image
var next = ((current.next().length) ? current.next() : $('#gallery img:first'));
//Set the fade in effect for the next image, show class has higher z-index
next.css({
opacity: 0.0
}).addClass('show').animate({
opacity: 1.0
}, 1000);
//Hide the current image
current.animate({
opacity: 0.0
}, 1000).removeClass('show');
}
我的反向代码如下所示:
$(document).ready(function() {
var current = $('#gallery img:last');
//Set the fade in effect for the next image, show class has higher z-index
current.addClass('show').css({
opacity: 0.0
}).animate({
opacity: 1.0
}, 1000);
setInterval('gallery()', 3000);
});
function gallery() {
//if no IMGs have the show class, grab the first image
var current = ($('#gallery img.show') ? $('#gallery img.show') : $('#gallery img:last'));
//Get next image, if it reached the end of the slideshow, rotate it back to the first image
var before = ((current.before().length) ? current.before() : $('#gallery img:last'));
//Set the fade in effect for the next image, show class has higher z-index
before.css({
opacity: 0.0
}).addClass('show').animate({
opacity: 1.0
}, 1000);
//Hide the current image
current.animate({
opacity: 0.0
}, 1000).removeClass('show');
}
答案 0 :(得分:1)
在没有测试页面的情况下,我在ul中添加了图像:
var before = ((current.prev().length) ? current.prev() : $('#gallery img:last'));
这将选择要显示的prev图像,如果没有,则再次选择最后一个图像。
你能试试这个吗?