简体   繁体   English

即使加载了window.load,document.ready也会运行

[英]document.ready runs even if window.load is loaded

What to write to check if window is fully loaded then do some functions and if not then do document.ready functions....ie : i have a preload image which appears if windows isn't fully loaded and i call it in document.ready .....and if window is fully loaded i hide this preload image....it runs correctly if window isn't fully loaded and disappear after window get loaded.....but document.ready get called even if window is already loaded ...so how to check if window is loaded then don't do document.ready and if not then do document.ready 要写什么来检查窗口是否已完全加载,然后执行某些功能,如果没有,则执行document.ready函数.....即:如果窗口未完全加载,并且在document.ready调用它,我会显示一个预加载图像document.ready ...并且如果窗口已完全加载,我会隐藏此预加载图像....如果窗口未完全加载,它将正确运行,并在窗口加载后消失.....但是document.ready会被调用,即使窗口已经加载...所以如何检查窗口是否已加载然后不执行document.ready ,否则不执行document.ready

$(document).ready(function (e) {
    $("#loding").css("visibility", "visible");
    $("body").css('overflow', 'hidden');
    $("#container").css("opacity", 0);
});
$(window).load(function (e) {
    $("#loding").animate({
        opacity: 0
    }, 500, function () {
        $("#loding").css("width", "70%");
        $("#loding").css("visibility", "hidden");
    });
    $("#container").css("opacity", 1);
    $("body").css('overflow', 'auto');
});

You could do something like this : 您可以这样做:

var loaded = false;
$(document).ready(function(e) {
   if(!loaded) {
     // only run here if the $(window).load() function hasnt run
   }

});
$(window).load(function(e) {
   // run your functions
   loaded = true;
});

uses a simple boolean to indicate if the loaded functions have run or not 使用一个简单的boolean指示加载的函数是否已运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM