隐藏所有内容,直到页面加载完成 [英] Hiding everything until the page has finished loading
问题描述
我希望隐藏页面上的所有内容,直到页面加载完成.我看过很多文章,尝试了不同的方法. 最有效的最常见解决方案是
I am looking to have everything on my page hidden until the page has finished loading. I have seen many posts and tried different things. The most common solution which works great is
<body style="display:none;">
然后运行jQuery以在窗口加载时再次显示它
Then run jQuery to show it again upon window load
$(window).load(function() {
$("body").fadeIn("slow");
});
我对此有疑问,因为该页面依赖JS来显示所有内容.我很欣赏这是一件罕见的事情,但是感觉很不对.
I have an issue with this, as the page is reliant on JS to show anything at all. I appreciate this is a rare thing, but just feels wrong.
理想情况下,我想使用jQuery添加display:也没有CSS
Ideally I would like to use jQuery to add the display:none css as well
但是...
问题是当我添加
$(document).ready(function {
$(body).css('display', 'none');
});
即使要花一些时间才能运行,并且页面内容之前也会闪烁.
Even this takes a while to run and the page flickers with content before hand.
有更好的方法吗?
我可以在没有document.ready的情况下使用上面的脚本吗(尝试过,但是没有用)
Could I use the above script without document.ready (tried, but didn;t work)
谢谢.
推荐答案
要使用javascript隐藏它,请在BODY标记声明之后设置脚本:
To hide it using javascript, set script just after BODY tag declaration:
<body>
<script>document.body.style.display = "none";</script>
这样,如果禁用了javascript,仍会显示BODY
This way if javascript disabled, BODY is still shown
这篇关于隐藏所有内容,直到页面加载完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!