繁体   English   中英

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

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

我的 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();

    });

});

你的代码说:

  • 加载文档
  • 当 DOM 被加载时,注册一个新的钩子来监听窗口被加载(图像等),这将启动动画

但是,当您的窗口加载注册发生时,窗口可能已经加载。

您还使用了错误的方法来订阅窗口加载事件。

尝试:

 $(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