簡體   English   中英

頁面加載 10 秒后顯示 div

[英]Show div after 10 seconds page load

我有這個腳本,我已經能夠在 20 秒內使其淡出,但我希望頁面加載后需要 10 秒才能顯示,我應該修改什么?

jQuery("#messageBox").hide().slideDown();
 setTimeout(function(){
  jQuery("#messageBox").fadeOut();        
 }, 20000);

提前致謝

要讓內容在 10 秒后淡入,您需要使用 CSS 隱藏頁面加載時的所有內容,以避免FOUC 問題,然后調用fadeIn() 像這樣的東西:

 setTimeout(function() { $('#container').fadeIn(); }, 10000);
 #container { display: none; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="container"> <h1>Lorem ipsum</h1> </div>

你正朝着正確的方向前進。 就像您應用淡出一樣。

您需要在setTimeout的幫助下在 10 秒后顯示您的div 但是您必須在頁面加載時默認隱藏此div

請參見下面的示例 -

 jQuery("#messageBox").hide(); setTimeout(function(){ jQuery("#messageBox").slideDown(); }, 10000); setTimeout(function(){ jQuery("#messageBox").fadeOut(); }, 20000);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="messageBox"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM