jQuery or [removed] Determine when image finished loading

后端 未结 7 960
不思量自难忘°
不思量自难忘° 2020-12-05 10:15

How can I detect when an image has finished loading be it from the server or the browser cache? I want to load various images in the same tag and d

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 11:09

    From a very similar question Official way to ask jQuery wait for all images to load before executing something and just like Pikrass says:

    With jQuery, you use $(document).ready() to execute something when the DOM is loaded and $(window).load() to execute something when all other things are loaded as well, such as the images.

    Here are two examples:

    DOM

    jQuery(document).ready(function(){
        console.log('DOM ready');
    });
    

    Images / Everything Else

    jQuery(window).load(function(){
        console.log('all other things ready');
    });
    

    You should be able to confirm in your console:

    screenshot-with-shadow.png http://img547.imageshack.us/img547/9681/yih.png

提交回复
热议问题