[英]Display div for 2 seconds after page load
Is possible to show a div for only 2 seconds when users come to my website? 用户访问我的网站时,能否仅显示2秒钟的div?
<div class="message">
<p>Hello, everybody this websites will be moved in 2 weeks</p>
</div>
maybe using jquery or javascript. 也许使用jQuery或JavaScript。
You can use setTimeout to hide the div after 2 seconds on document.ready 您可以在文档上2秒钟后使用setTimeout隐藏div。
$(document).ready(function(){
setTimeout(function(){ $(".message").hide(); }, 2000);
});
You can use fadeOut to animate the disappearance of the div. 您可以使用fadeOut来动画div的消失。
Try this function, which will hide the div after 2 seconds 尝试此功能,它将在2秒后隐藏div
setTimeout(function() {
$('.message').fadeOut('fast');
}, 2000); // <-- time in milliseconds
If you use "hide", the element would not be visible, but the space it ocupies will still be there. 如果您使用“隐藏”,则该元素将不可见,但它所占据的空间仍将存在。 Changing the attribute to "display: none", you will hide it while the empty space will disappear.
将该属性更改为“ display:none”,您将隐藏它,而空白将消失。
$(document).ready(function(){
setTimeout(function(){ $(".message").attr("display", "none"); }, 2000);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.