jQuery 显示 5 秒然后隐藏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3428766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery show for 5 seconds then hide
提问by josoroma
I'm using .show
to display a hidden message after a successful form submit.
我.show
用来在成功提交表单后显示隐藏消息。
How to display the message for 5 seconds then hide?
如何显示消息5秒然后隐藏?
回答by Nick Craver
You can use .delay()
before an animation, like this:
您可以.delay()
在动画之前使用,如下所示:
$("#myElem").show().delay(5000).fadeOut();
If it's not an animation, use setTimeout()
directly, like this:
如果不是动画,setTimeout()
直接使用,像这样:
$("#myElem").show();
setTimeout(function() { $("#myElem").hide(); }, 5000);
You do the second because .hide()
wouldn't normally be on the animation (fx
) queue without a duration, it's just an instant effect.
你做第二个是因为.hide()
通常不会在fx
没有持续时间的情况下出现在动画 ( ) 队列中,它只是一个即时效果。
Or, another option is to use .delay()
and .queue()
yourself, like this:
或者,另一种选择是使用.delay()
和.queue()
你自己,就像这样:
$("#myElem").show().delay(5000).queue(function(n) {
$(this).hide(); n();
});
回答by Rahul
You can use the below effect to animate, you can change the values as per your requirements
您可以使用以下效果进行动画制作,您可以根据需要更改值
$("#myElem").fadeIn('slow').animate({opacity: 1.0}, 1500).effect("pulsate", { times: 2 }, 800).fadeOut('slow');