簡體   English   中英

頁面加載后顯示div 2秒

[英]Display div for 2 seconds after page load

用戶訪問我的網站時,能否僅顯示2秒鍾的div?

<div class="message">
   <p>Hello, everybody this websites will be moved in 2 weeks</p>
</div>

也許使用jQuery或JavaScript。

您可以在文檔上2秒鍾后使用setTimeout隱藏div。

$(document).ready(function(){
    setTimeout(function(){ $(".message").hide(); }, 2000);
});

您可以使用fadeOut來動畫div的消失。

嘗試此功能,它將在2秒后隱藏div

setTimeout(function() {
    $('.message').fadeOut('fast');
}, 2000); // <-- time in milliseconds

如果您使用“隱藏”,則該元素將不可見,但它所占據的空間仍將存在。 將該屬性更改為“ display:none”,您將隱藏它,而空白將消失。

$(document).ready(function(){
    setTimeout(function(){ $(".message").attr("display", "none"); }, 2000);
});

暫無
暫無

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

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