【发布时间】:2012-05-30 22:40:19
【问题描述】:
我的画廊有缩略图,它们都有对应的同名较大图像,我使用 php 将每个拇指动态链接到其较大的图像。然后我使用jQuery使用href属性显示更大的图像,以获得大图像的路径。当灯箱弹出并单击下一个时,它应该允许我浏览并查看每个图像,而不是当仅单击下一个时,它会转到下一个图像,但如果再次单击下一个,它会显示相同的图像。
我附上了图片来给出一个基本的想法,因为我不擅长解释。
在我的画廊中动态加载的缩略图:
当单击图库中的最后一个拇指时,会弹出以下内容(建筑物的图片):
点击下一张时,会显示这张照片(破灭的泡泡),但是点击几次下一张,这张照片(破灭的泡泡)仍然存在:
我的代码:
var Picture = $('.lightbox'); // path to full sized picture the class lightbox identifies a link <a>
var pic = Picture.index(this) //finds index
var num = Picture.length;//finds the total amount of thumbnails
$('#next').click(function(e){ //when next is click prevent default
e.preventDefault();
if(pic<(num-1)){
var ntx = (pic)+1;
}
if(pic == (num-1)){
ntx= 0;
}
var nxt = Picture[ntx];
var img = $('.box img');
img.remove();
$('.box').hide(); // removes the current image
$('.box').append('<img align="center" id="motown" src="'+nxt+'" style=" z-index:52px;" > '); //appends the next image and sets the div container to hidden and hide the new image
});
我可以在我的代码中添加什么来使下一个按钮每次都能正常工作?
【问题讨论】:
-
num变量返回什么? -
@ZeeTee 它返回缩略图的总数。
-
最好在 jsfiddle 中进行设置:jsfiddle.net
-
我做了,但没有正确显示,所以我放弃了这个想法。会再试一次
-
@user1381778 您使用的是什么版本的 jQuery?试试
$('#next').live('click', function(e){ .... })。