我正在做Jquery的幻灯片。它列出缩略图,当点击,显示大图像的叠加。为了匹配与大图片我添加属性,每个缩略图和大图片大拇指。的属性包含一个数,其中每个拇指到其相应的大的图像相匹配。它的工作原理,当一个幻灯片出现在页面上。但我想它如果有一个以上的幻灯片存在工作。

下面是用于添加属性大拇指和放大图的代码:

thumbNo = 0;
largeNo = 0;
$('.slideshow_content .thumbs img').each(function() {            
   thumbNo++;
   $(this).attr('thumbimage', thumbNo);
   $(this).attr("title", "Enter image gallery");
});
$('.slideshow_content .image_container .holder img').each(function() {   
   largeNo++;
   $(this).addClass('largeImage' + largeNo);
});

此工作。为了使增量工作的时候有两个幻灯片页面上,我认为我可以在这个贴代码中的每个函数...

$('.slideshow').each(function() {
    thumbNo = 0;
    largeNo = 0;
    $(this + '.slideshow_content .thumbs img').each(function() {            
       thumbNo++;
       $(this).attr('thumbimage', thumbNo);
       $(this).attr("title", "Enter image gallery");
    });
    $(this + '.slideshow_content .image_container .holder img').each(function() {   
       largeNo++;
       $(this).addClass('largeImage' + largeNo);
    });
});

这里的问题是,操作者incrimenting不重置为所述第二幻灯片的div(.slideshow),所以我结束了在第一.slideshow DIV大拇指被编号为1,2,3等。和拇指在第二.slideshow格编号为4,5,6等,如何让我在第二.slideshow DIV复位的数字,并从1重新开始?

这是真的很难简明解释。我希望有人得到的要点。

有帮助吗?

解决方案

在你的每一个下井的水平,确保它的作用域像这样每个幻灯片:

$('.slideshow_content').each(function() {
    thumbNo = 0;
    largeNo = 0;
    $(this).find('.thumbs img').each(function() {
       $(this).attr('thumbimage', thumbNo++);
       $(this).attr("title", "Enter image gallery");
    });
    $(this).find('.image_container .holder img').each(function() {   
       $(this).addClass('largeImage' + largeNo++);
    });
});

此它们设置为0的每个.slideshow_content块内并在其内部循环整体设置它,然后通过所有块循环,而不是

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top