在页面加载时隐藏div吗? [英] Hide a div while page is loading?

查看:192
本文介绍了在页面加载时隐藏div吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个div加载起来很有趣,我的客户对此有点担心,但是我想帮助他们.

So I've got one div that loads kind of funny, and my client is a little concerned about it, but I want to help them out.

有没有一种方法可以在jQuery的设置时间内隐藏div?可能只是不透明度:页面加载时为0,然后输入2秒,将其更改为不透明度:1.

Is there a way I can hide a div for a set time with jQuery? probably just opacity: 0 on page load, then 2 seconds in, change it to opacity: 1.

另一种选择是添加/删除类方法.我只是不确定要在页面加载时使其处于一种状态,然后无限期地处于另一种状态(当然,除非刷新页面)的代码是什么,所以类似

An alternative might be to add/remove class method. I'm just not sure what the code would be to have it in one state while the page loads, then in the other state indefinitely (unless the page is refreshed of course) so something like

jQuery('#DIV').WHILELOADING(function() {
    jQuery('#DIV').addClass('hidden_div')
});

jQuery('#DIV').AFTER_2_SECONDS(function() {
    jQuery('#DIV').removeClass('hidden_div')
});

我只是不完全确定如何执行此操作.同样,我不知道该怎么做的加载屏幕",大声笑. :P

I'm just not 'entirely' sure how to do this. As well, a "loading screen" which I know how to do, is out of the question, lol. :P

推荐答案

如何加载div,如果是页面加载,则只需将div隐藏在页面加载中并在

How is the div is being loaded, If it is page load then simply have the div hidden on page load and show the div inside

  jQuery(window).load (function () { 
      jQuery('#DIV').removeClass('hidden_div')
  });

如果使用.load(ajax调用)加载div,则使用.load回调显示div.

If you are loading the div using .load (ajax call) then used .load callback to show the div.

jQuery('#DIV').load('<URL>', function() {
   jQuery('#DIV').removeClass('hidden_div')
});

以上两个假设您已隐藏了div,如下所示,

Above two as assuming that you have the div hidden like below,

<div id="DIV" class="hidden_div"><!-- div content --> </div>

注意:添加延迟可能不会给您带来一致的结果.例如:如果延迟是5秒,页面加载需要10秒,那么您将遇到同样的问题.

Note: Adding delay may not give you a consistent result. For ex: If the delay is 5 sec and page take 10 secs to load then you going to have the same issue.

它是由PHP生成的HTML而不是jQuery加载的.我正在关注 首先发表评论,这样的话? "jQuery('#DIV').delay(1000).removeClass('hidden_​​div');"

It's just loaded by PHP generated HTML, not jQuery. I am following the first comment, so something like this? "jQuery('#DIV').delay(1000).removeClass('hidden_div');"

如果是php生成的代码,则在生成代码的末尾回显removeClass代码.

If it is php generated code then echo the removeClass code at the end of the generating code.

这篇关于在页面加载时隐藏div吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆