我需要遍历每个容器中的所有项目,每次循环到达新容器时从1开始。
编辑:添加了JSFiddle http://jsfiddle.net/ntv4k4LL/
E.g。
Container
- 1
- 2
- 3
Container
- 1
- 2
- 3
但目前正在进行
Container
- 1
- 2
- 3
Container
- 4
- 5
- 6
这是我的代码:
$('.index-slide-rel').each(function(){
$(this).children('article').each(function(i,e){
col++;
if(i > 0 && i%cols === cols-1) {
sx= 0;
row++;
col=1;
sy += previewElementHeight;
}
})
});
答案 0 :(得分:3)
$('.index-slide-rel').each(function(i, container) {
// here, i should take the value 0 to 1, considering you have 2 containers.
$(container).children('article').each(function(j, element) {
// here, j should take the value 0 to 2, considering you have 3 elements.
});
});