javascript jquery 显示 div 10 秒

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7189751/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 23:14:53  来源:igfitidea点击:

Jquery show div for 10 seconds

javascriptjquery

提问by user892239

  $(window).load(function(){
  $("#loading").show(10); //it was hide but changed to show, not working


  <div id="loading">
  Loading content, please wait..
  <img src="loading.gif" alt="loading.." />
  </div>

how can I get this loading bar to show for 10 seconds?

我怎样才能让这个加载栏显示 10 秒?

any help is greatly appreciated!

任何帮助是极大的赞赏!

回答by user113716

If you meant that it's currently showing, and you want it to hideafter 10 seconds, do this:

如果您的意思是它当前正在显示,并且希望它在 10 秒后隐藏,请执行以下操作:

$("#loading").delay(10000).hide(0);

Or if you actually wanted an animation with the .hide(), add a longer duration:

或者,如果您确实想要带有 的动画.hide(),请添加更长的持续时间:

$("#loading").delay(10000).hide(400);

回答by Jamiec

 $('#loading').delay(10000).fadeOut();

If you dont want to fade out you can also do

如果你不想淡出你也可以这样做

 $('#loading').delay(10000).queue(function(){ $(this).hide();$(this).dequeue(); });

Docs:

文档:

回答by Prisoner

setTimeout(function(){ $("#loading").fadeOut(); }, 10000);

回答by Bhanu Krishnan

Use Jquerydelay

使用 Jquery延迟

   $("#loading").show().delay( 10000 ).hide();

回答by Artur Keyan

$('#loading').animate({ opacity: 1 }, 10000);

回答by Tijo K Varghese

You can add this code...

您可以添加此代码...

$("#loading").show(10000,function(){
$("#loading").hide();
});

<div id="loading" style="display:none;">
  Loading content, please wait..
<img src="loading.gif" alt="loading.." />
</div>

this will display the div only for 10 second.. after 10 second div will disappear..

这将只显示 10 秒的 div.. 10 秒后 div 将消失..