Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
951 views
in Technique[技术] by (71.8m points)

jquery - 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;">

Then run jQuery to show it again upon window load

$(window).load(function() {
  $("body").fadeIn("slow");
});

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.

Ideally I would like to use jQuery to add the display:none css as well

however...

The problem is when I add

$(document).ready(function {
  $(body).css('display', 'none');
});

Even this takes a while to run and the page flickers with content before hand.

Is there a better way?

Could I use the above script without document.ready (tried, but didn;t work)

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To hide it using javascript, set script just after BODY tag declaration:

<body>
    <script>document.body.style.display = "none";</script>

This way if javascript disabled, BODY is still shown


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...