jQuery隐藏()div直到完全加载

问题描述:

我正在使用选项卡式功能发布我的博客。如何实现div#latest-featuredhide()然后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,我想隐藏它,直到内容满载,然后再显示回来一切都被加载后。

如何实现上面的当前代码。

+0

你想去哪里使用'#latest -featured'?我在你的代码中看不到任何线索。 – Sarfraz 2010-08-10 18:40:11

+0

ok更新为html – kampit 2010-08-10 18:47:42

可能最好做这样的事情:

<div id="latest-features" style="display:none;"></div> 

$(function() { 
    // do work 
    $("div#latest-featured").show(); 
} 

它通常不是一个好主意,默认隐藏任何东西,但这样会满足您的要求。

+0

感谢猎人..它的工作。如何做到一个好主意? – kampit 2010-08-10 18:54:53

+4

这个问题是如果你的javascript弄错了或者浏览器不支持js这个项目永远不会显示。 – hunter 2010-08-10 19:14:53

为什么不直接设置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();

罗伯特回答了最好的,我会投它,但还不能...望着这个解决方案几个小时,这是最好的,我发现...