2011-12-24 94 views
0

在下面的代碼中,頁面會淡入,然後它會在左側的列表項中淡入,然後它會在右側的每個縮略圖中淡入。但由於我使用.delay(),它最終會跳過部分或全部縮略圖的加載。除了.delay()之外,還有別的東西可以用來在開始之前暫停大拇指的執行嗎?延遲的奇怪行爲?

//Showcase 
    $('#showcase').animate({'opacity' : 0}, 0); 
    fadeInDivs(['#showcase']); 
    function fadeInDivs(els) { 
     e = els.pop(); 
     $(e). delay(750).animate({'opacity' : 1}, 1000, function(){ 
      if (els.length) fadeInDivs(els); 
     }); 
    }; 

    $('#showcase').queue(function(){ 

     //fade in each filter 
     $('#filters li').each(function(i, item) { 
      setTimeout(function() { $(item).animate({'opacity' : 1}, 1000); }, 50 * i); 
     }); 

     //fade in each thumbnail 
     $('.thumb').delay(1000).each(function(i, item) { 
      setTimeout(function() { $(item).animate({'opacity' : 1}, 1000); }, 500 * i); 
     }); 
    }); 

回答

1

試試這個fiddle。我想這是你在找什麼。讓我知道如果它不是。這裏是jQuery代碼:

$('#showcase').queue(function() { 
    var i = 0; 
    var length = $('#filters li').length; 
    //fade in each filter 
    $('#filters li').each(function(i) { 

     //alert(i); 
     $(this).delay(750*i).animate({ 
      'opacity': 1 
     }, 1000, function() { 
      if (i == length) { 
       //fade in each thumbnail 
       $('.thumb').each(function(i) { 
        $(this).delay(750 * i).animate({ 
         'opacity': 1 
        }, 1000); 
       }); 
      } 
     }); 
     i++; 
    }); 

}); 
+0

IM試圖讓#filters裏當做到這一點我想.thumbs淡入到,然後褪色..繼承人小提琴http://jsfiddle.net/UsXWn /因爲你看到照片開始消失在過濾器完成之前 – 2011-12-24 04:45:08

+0

@JoeBobby - 我更新了小提琴。看看這是否更符合你的喜好。 – john 2011-12-24 04:54:30

+0

有沒有辦法通過改變.queue()中的部分來實現?是否有一個原因,你爲什麼從動畫改爲淡入? – 2011-12-24 05:32:48