开发者

Hide Body until Content is Loaded -- Works on IE, but not Safari?

开发者 https://www.devze.com 2023-04-13 09:50 出处:网络
Here\'s a weird one -- something that works great in IE, but not in Safari.Here\'s my code: <script type=\"text/javascript\">

Here's a weird one -- something that works great in IE, but not in Safari. Here's my code:

<script type="text/javascript">
 $(document).ready(function(){
 $('body').css('display', 'block');
 });</script>

</head>
<body style="margin:0; display:none;">

The goal is to set the body display to none 开发者_运维百科until the document is ready. Then change the display property to block.

Any idea what I'm doing wrong here?


CAN I ADD some sort of conditional code, such that if javascript is not enabled it loads immediately, but if it is enabled it waits to display until the document is ready?

Yes, you can:

<script type="text/javascript">
 $(function(){
   $('body').css('display', 'block');
 });
</script>
</head>
<body>
<script type="text/javascript">
  $('body').css('display','none'); // this will execute before $(document).ready()
</script>


You should use jQuery's .load() if you want the page to really be ready (images loaded too) before displaying it. On the other hand, you shouldn't hide the body at all with css, as people with javascript turned off will assume the site just crashed. Unless of course you're creating a 100% javascript dependent application.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号