How to do jquery code AFTER page loading?

前端 未结 8 1855
庸人自扰
庸人自扰 2020-12-22 19:07

If you want an event to work on your page, you should call it inside the $(document).ready() function. Everything inside it will load as soon as the D

相关标签:
8条回答
  • 2020-12-22 19:51

    Edit: This code will wait until all content (images and scripts) are fully loaded and rendered in the browser.

    I've had this problem where $(window).on('load',function(){ ... }) would fire too quick for my code since the Javascript I used was for formatting purposes and hiding elements. The elements where hidden too soon and where left with a height of 0.

    I now use $(window).on('pageshow',function(){ //code here }); and it fires at the time I need.

    0 讨论(0)
  • 2020-12-22 19:55

    Following

    $(document).ready(function() { 
    });
    

    can be replaced

    $(window).bind("load", function() { 
         // insert your code here 
    });
    

    There is once more way which i'm using to increase the page load time.

    $(document).ready(function() { 
      $(window).load(function() { 
         //insert all your ajax callback code here. 
         //Which will run only after page is fully loaded in background.
      });
    });
    
    0 讨论(0)
提交回复
热议问题