weixin_33701251 2012-08-22 15:33 采纳率: 0%
浏览 26

未显示“正在加载”图片

I have a div on my page with the following css:

.modal {
    display:    none;
    position:   fixed;
    z-index:    1000;
    top:        0;
    left:       0;
    height:     100%;
    width:      100%;
    background: rgba( 255, 255, 255, .35 ) 
                url('/NoAuth/cf/ajax-loader.gif')
                50% 50% 
                no-repeat;
}


/* Anytime the body has the loading class, our
   modal element will be visible */
body.loading .modal {
    display: block;
}

And I add or remove the "loading" class on the body when a .ajax call is made using:

jQuery(document).ready(function () {
    jQuery('body').on({
      ajaxStart: function() {
        jQuery(this).addClass('loading');
      },
      ajaxStop: function() {
        jQuery(this).removeClass('loading');
      }
    });
});

But much of the time, I find during the ajax call, the background changes color, but the gif doesn't show up. If, however, I go to the Firebug console and type jQuery('body').addClass('loading'), the image does show up. And when I look at the "Net" tab in Firebug, it shows that it didn't load the gif until I typed that .addClass command.

Is there something I need to do to pre-load that background so it shows up all the time, or what can I do to prevent this problem?

  • 写回答

2条回答 默认 最新

  • weixin_33716154 2012-08-22 15:46
    关注

    Maybe it's because of the display:none CSS attribute. Why don't you make it invisible when the document is ready ? The loading would appear during the loading of the document. Just remove the display attribute in .modal

    And the javascript :

    jQuery(document).ready(function () {
        jQuery('body .modal').hide();
        jQuery('body').on({
          ajaxStart: function() {
            jQuery(this).addClass('loading');
          },
          ajaxStop: function() {
            jQuery(this).removeClass('loading');
          }
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器