2010-09-07 47 views

回答

1

可以逆转扭转阵列顺序.each()电话,和其他一些优化,比如:

(function($) { 
$.fn.fadeInSequence = function(fadeInTime, timeBetween) { 
    //Default Values 
    timeBetween = timeBetween || 0; 
    fadeInTime = fadeInTime || 500; 

    //The amount of remaining time until the animation is complete. 
    //Initially set to the value of the entire animation duration. 
    var l = this.length, remainingTime = l * (fadeInTime+timeBetween); 

    $.each(this.get().reverse(), function(i) { 

     //Wait until previous element has finished fading and timeBetween has elapsed 
     $(this).delay(i*(fadeInTime+timeBetween)); 

     //Decrement remainingTime 
     remainingTime -= (fadeInTime+timeBetween); 

     if($(this).css('display') == 'none') 
     { 
      $(this).fadeIn(fadeInTime); 
     } 
     else //If hidden by other means such as opacity: 0 
     { 
      $(this).animate({'opacity' : 1}, fadeInTime); 
     } 

     //Delay until the animation is over to fill up the queue. 
     $(this).delay(remainingTime+timeBetween); 
    }); 
    return this; 
}; 

})(jQuery); 

Here's a copy the demo page updated to use the backwards version

+0

谢谢,非常简单的解决方案! – c4rrt3r 2010-09-07 14:58:18