window load inside a document ready?

前端 未结 4 1922
盖世英雄少女心
盖世英雄少女心 2020-12-13 05:03

Sorry if this has been answered before but all searches talk about the differences, not about using the two together, if possible.

Simply, can $(window).load.(

4条回答
  •  一向
    一向 (楼主)
    2020-12-13 05:30

    WARNING: The answers in this question are quite outdated.

    As @ViRuSTriNiTy mentioned in comments that this code is no longer valid in jQuery 3 and it was mentioned as an issue on GitHub.

    So this method is not advised anymore.

    One way to do it is to use the following code

    $(window).on("load", function(){
       $.ready.then(function(){
          // Both ready and loaded
       });
    })
    

    However, this code won't work if you load images in ready and want to call some code after it is fully loaded.

提交回复
热议问题