代码有错吗? i 一循环到7就出现错误
//我没有oBoxw .是直接获取了存到oParent //其他地方都没错. 就hArr数组第七个图片开始就没了..我是一排6张图 var hArr=[]; for(var i=0;i<oParent.length;i++){ console.log(i); if(i<cols){ hArr.push(oParent.eq(i).outerHeight()); }else{ var minH=Math.min.apply(null,hArr);//求数组最小值,图片最小高度 console.log(minH); var index=$.each(hArr,function(i,n){ if(n==minH) return i;//最小值的索引 }); oParent.eq(i).css({'position':'absolute','top':minH,'left':oBoxW*index}); //left可设置oParent.eq(i).offset().left; hArr[index]+=oParent.eq(i).height(); console.log(hArr[index],oParent.eq(i).height()); } } //六张图片高度 console.log(hArr,length); } //六张图片高度 console.log(hArr,length);
google调试:
1
2
3
4
5
6
NaN 150
7
NaN 278
8
NaN 150
9
NaN 278
10
NaN 150
11
NaN 278
12
NaN 150
13
NaN 278
14
NaN 150
15
NaN 278
16
NaN 150
17
NaN 278
[165, 293, 165, 293, 165, 293, 165,293,165,293,165,293: NaN] 0