javascript - jquery 在加载时导致 “white”

标签 javascript jquery css

我在论坛上搜索了一下,似乎无法弄清楚如何解决加载新页面时白色闪烁的常见问题。

我试过 Chris Coyer 的例子,将它放在我的其他 javascript 之上:

    // Prevent variables from being global
(function () {

      /*
          1. Inject CSS which makes iframe invisible
      */

    var div = document.createElement('div'),
        ref = document.getElementsByTagName('base')[0] ||
              document.getElementsByTagName('script')[0];

    div.innerHTML = '&shy;<style> iframe { visibility: hidden; } </style>';

    ref.parentNode.insertBefore(div, ref);

    /*
        2. When window loads, remove that CSS,
           making iframe visible again
    */

    window.onload = function() {
        div.parentNode.removeChild(div);
    }

})();

但是,还在闪烁。我是 javascript 的菜鸟,所以我不太确定我做错了什么。

最差的页面是:http://thegoodgirlsnyc.com/test/new/index3_7.php

最佳答案

如果您使用的是 Jquery,请尝试使用以下方法包装您的函数:

$(document).ready(function(){
 /* Code goes here */
});

这将在文档准备好(完全加载)时执行您的代码

关于javascript - jquery 在加载时导致 “white”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6876584/

相关文章:

javascript - 无法让 $(window).load() 在加载到 div 的页面上工作

html - 如何在 div 元素内将图像居中 (HTML)

php - 使用javascript更改php包含路径

jquery - 为什么带有 z-index 的表没有显示在其他表之上?

javascript - Ember 找不到模板

javascript - 统计 json 文件中名称出现的次数

php - Bootstrap 下拉菜单不适用于包含 header php

javascript - css 字体声明的正则表达式

javascript - 产生了一个不能被视为 promise 的值(value)

javascript - 默认选择一行并使用 jQuery DataTables 发送 XHR 请求