简体   繁体   English

为什么我的 $(window).load(function() 在 document.ready 函数中不起作用?

[英]why my $(window).load(function() is not working in document.ready function?

my on windows.load function not working in document.ready我的 windows.load 函数在 document.ready 中不起作用

$(document).ready(function(){

       //this is for nimation
       $(".progress-bar-fill").css({"width":"100%","transition":"5s"});
      // my this function is not working
       $(window).load(function() {
        $(".overlay").fadeOut();

    });

});

Your code says:你的代码说:

  • Load the document加载文档
  • When the DOM is loaded, register a new hook to listen on when the window is loaded (images etc.) which will start the animation当 DOM 被加载时,注册一个新的钩子来监听窗口被加载(图像等),这将启动动画

However, by the time your window load registration happens, the window might already be loaded.但是,当您的窗口加载注册发生时,窗口可能已经加载。

You also use the incorrect method to subscribe to the window loaded event.您还使用了错误的方法来订阅窗口加载事件。

Try:尝试:

 $(document).ready(function(){ //this is for nimation $(".progress-bar-fill").css({"width":"100%","transition":"5s"}); }); $(window).on("load", function() { $(".overlay").fadeOut(); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script> <div class="progress-bar-fill">progress bar</div> <div class="overlay">overlay</div>

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

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