Delay some jQuery function until all images are loaded completely

后端 未结 2 670
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 08:05

How do I delay some jQuery / JavaScript function until all the images on a page have finished loading? Actually, the jQuery function I\'m talking about is for setting the offset

2条回答
  •  天命终不由人
    2021-01-24 08:18

    You can use the onload event which runs after all images or external resources are loaded:

    $(window).load(function(){
      // your code here, all images loaded
    });
    

    You can also use the load event for individual images and run your code when they have loaded:

    $('img.ImageClass').load(function(){
      // The image loaded....
    });
    

提交回复
热议问题