javascript - $(window).load 刷新时的奇怪行为

标签 javascript jquery

我有一个加载掩码,我想在整个页面加载后淡出()。它在用户第一次进入页面时完美运行,但如果刷新,加载掩码会在页面加载之前消失。我读过很多文章,似乎常见的问题是 $(window)load 通常不会因为缓存而触发事件,但在我的情况下,它在刷新时触发得太快......可能是什么问题是什么?

 1. <html>
   2.       <head><script type="text/javascript">
   3.             Ext.onReady(function() {....});
   4.             $(window).load(function(){$('#loading-mask').fadeOut(5000); $('#loading').fadeOut(5000);});
   5.       </script></head>
   6.       <body>
   7.             <div id="loading-mask"></div>
   8.             <div id="loading">
   9.                   <span id="loading-message">Loading Tibet...</span>
  10.              </div>
  11.       </body>
  12.  </html>

任何帮助或指导将不胜感激:)

谢谢

艾尔莎

最佳答案

好吧,我发现最好将 JavaScript 代码放在正文中..

现在我的所有代码都在正文中,包括 Ext.onReady,所以这里...

    <html>
        <head></head>
        <body onload="">

            <div id="loading-mask"></div>
            <div id="loading">
              <span id="loading-message">Loading Tibet...</span>
            </div>
            <script type="text/javascript">

            //Default blank image needed for some ExtJS widgets/if no image is found...
            Ext.BLANK_IMAGE_URL = "./ext-3.2.1/resources/images/default/s.gif";

            Ext.onReady(function() {
                .............
             });

//Outside Ext.onReady
 window.onload = function(){$('#loading-mask').fadeOut(5000); $('#loading').fadeOut(5000);}

</body></html>

//The css is:

#loading-mask {
     position: absolute;
     top: 0;
     left: 0;
     width: 100%;
     height: 100%;
     /*background: #D8D8D8;*/
    /* background: #6E6E6E;*/
    background: #000000;
     opacity: .8;
     z-index: 1;
}
#loading {
     position: absolute;
     top: 40%;
     left: 45%;
     z-index: 2;
}
#loading span {
     /*background: url('ajax-loader.gif') no-repeat left center;*/
     background: url('globe.gif') no-repeat left center;
     color: #BDBDBD;
     width: 60%;
     height: 30%;
     padding: 60px 70px;
     display: block;
}

关于javascript - $(window).load 刷新时的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4380856/

相关文章:

javascript - 将查询字符串添加到 data-href

javascript - 将#hash 标记更改为在页面加载时链接

jquery - "Uncaught TypeError: Failed to execute ' getComputedStyle ' on ' 窗口 ': parameter 1 is not of type ' 元素'.Tq ​​@ VM107 :37mF , 当 gmap 添加时

javascript - 更新已实例化的图表数据

javascript - 现在使用 WordPress 中的 GM api 在谷歌地图上显示标记

javascript - 如何在滚动时将 navbar-default 更改为 navbar-inverse?

javascript - 如何从函数效果中排除元素

javascript - package.json 中 main 的路径应该指向哪里?

javascript - firefox/safari/ie 上边距,左边距 0

javascript - 正则表达式 - 处理括号