[英]Show div after 2 seconds of page load
I am currently trying to show a div 2 seconds after the page is loaded. 我目前正在尝试在页面加载后2秒显示div。 I can successfully do the reverse by hiding the div two seconds after the page loads. 我可以通过在页面加载后两秒隐藏div来成功地执行相反操作。 The issue is that nothing occurs and the div stays hidden. 问题是没有任何事情发生,div保持隐藏。 How can I properly show a div after two seconds of page load? 如何在页面加载两秒后正确显示div? Extra: mean while the two seconds are running show an ajax loading gif and then fade in the div 额外:意味着两秒钟运行时显示ajax加载gif然后淡入div
<script type = "text/javascript">
$(window).load(function() {
setTimeout(function() {
$("#contentPost").show('fadeIn', {}, 500)
}, 2000);
});
</script>
html/css HTML / CSS
<style>
.contentPost { display:none;}
</style>
<div class="contentPost">
<h2>Hi there</h2>
</div>
$(document).ready(function() {
$(".contentPost").delay(2000).fadeIn(500);
});
Will work perfectly. 会很完美。
Ive never seen your show method written like that. 我从来没有见过这样的show方法。 Try altering it into use the jquery method fadeIn : 尝试改变它以使用jquery方法fadeIn :
<script>
$(function() {
$("#contentPost").delay(2000).fadeIn(500);
});
</script>
The show method does not accept any arguments and won't work as you want it to. show方法不接受任何参数,并且不会按您的意愿工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.