jQuery隐藏()div直到完全加载
问题描述:
我正在使用选项卡式功能发布我的博客。如何实现div#latest-featured
将hide()
然后show()
内容完全加载后返回?jQuery隐藏()div直到完全加载
$(document).ready(function() {
//Default Action
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
//On Click Event
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
return false;
});
});
HTML
<ul class="tabs">
<li><a href="#f1">Title 1</a></li>
<li><a href="#f2">Title 2</a></li>
</ul>
<div id="latest-featured">
<div id="f1" class="tab_content">
<p>Content for title 1</p>
<p>Why I want to hide the #latest-featured because.. when had image @ script here.. the tab_content will collapse all and break my design</p>
</div>
<div id="f2" class="tab_content">
<p>Content for title 1</p>
<p>Why I want to hide the #latest-featured because.. when had image @ script here.. the tab_content will collapse all and break my design</p>
</div>
</div>
比如我有id为#latest-featured
一个div,我想隐藏它,直到内容满载,然后再显示回来一切都被加载后。
如何实现上面的当前代码。
答
为什么不直接设置div显示:none直到你加载数据,然后删除display:none ...有很多方法可以做我刚刚提到的btw(例如,jQuery .toggle(true ))
答
如果您希望它显示加载后声明该div的CSS display: none
,然后在$(document).ready函数中调用$('div#latest-featured').show();
。
答
如果您希望它显示一次加载声明CSS显示:无该div,然后在$(document).ready
函数中调用$('div#latest-featured').show();
。
罗伯特回答了最好的,我会投它,但还不能...望着这个解决方案几个小时,这是最好的,我发现...
你想去哪里使用'#latest -featured'?我在你的代码中看不到任何线索。 – Sarfraz 2010-08-10 18:40:11
ok更新为html – kampit 2010-08-10 18:47:42