Checking for multiple images loaded

后端 未结 7 2231
死守一世寂寞
死守一世寂寞 2021-02-20 09:26

I\'m using the canvas feature of html5. I\'ve got some images to draw on the canvas and I need to check that they have all loaded before I can use them.

I have declared

7条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-20 10:03

    Use the window.onload which fires when all images/frames and external resources are loaded:

    window.onload = function(){
      // your code here........
    };
    

    So, you can safely put your image-related code in window.onload because by the time all images have already loaded.

    More information here.

提交回复
热议问题