Answers:
更新:从jQuery 1.4开始,您可以使用.delay( n )方法。http://api.jquery.com/delay/
$('.notice').fadeIn().delay(2000).fadeOut('slow'); 注意:$.show()并且$.hide()默认情况下不排队,因此,如果要$.delay()与它们一起使用,则需要以这种方式配置它们:
$('.notice')
    .show({duration: 0, queue: true})
    .delay(2000)
    .hide({duration: 0, queue: true});
您可能会使用Queue语法,这可能会起作用:
jQuery(function($){ 
var e = $('.notice'); 
e.fadeIn(); 
e.queue(function(){ 
  setTimeout(function(){ 
    e.dequeue(); 
  }, 2000 ); 
}); 
e.fadeOut('fast'); 
}); 
或者您可能真的很聪明,可以使用jQuery函数来做到这一点。
(function($){ 
  jQuery.fn.idle = function(time)
  { 
      var o = $(this); 
      o.queue(function()
      { 
         setTimeout(function()
         { 
            o.dequeue(); 
         }, time);
      });
  };
})(jQuery);
从理论上讲,这将允许您这样做:
$('.notice').fadeIn().idle(2000).fadeOut('slow'); @strager的好东西。像这样将其实现到jQuery中:
jQuery.fn.wait = function (MiliSeconds) {
    $(this).animate({ opacity: '+=0' }, MiliSeconds);
    return this;
}
然后将其用作:
$('.notice').fadeIn().wait(2000).fadeOut('slow');Ben Alman为jQuery写了一个不错的插件doTimeout。它有很多不错的功能!
只需使用几行jQuery即可完成此操作:
$(function(){
    // make sure img is hidden - fade in
    $('img').hide().fadeIn(2000);
    // after 5 second timeout - fade out
    setTimeout(function(){$('img').fadeOut(2000);}, 5000);
});
请参阅下面的小提琴以获取工作示例...