我正在尋找一種方法來加載頁面上的幾個隱藏的縮略圖(大約500),計算它們的總寬度,並在全部加載後顯示它們的容器。用回調加載幾個圖像()
問題是容器在全部加載之前一直顯示。
下面是簡單的代碼片段,我從我的腳本中提取:
// $('#thumbScroller') is the container, and is initially hidden.
var imgs = ['http://www.google.com/images/nav_logo95.png', 'http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=4'];
for(var i = 0; i < i.length; i++){
var url = imgs[i];
$('#thumbScroller').append('<img src="' + url + '" class="thumb" />');
// all elements were appened at this point
if(i == $this.totalImages-1){
//variable to hold total container width
var totalContent=0;
// loop through images to calculate total width
$('#thumbScroller img').each(function (s) {
totalContent += $(this).width();
//last image, show interface elements
if(s == $('#thumbScroller img').length-1){
$('#thumbScroller').width(totalContent).fadeIn();
};
});
}
}
任何幫助,將不勝感激!
將.hidden類添加到for之前的.interface元素。 –