Javascript - execute after all images have loaded

前端 未结 9 1337
陌清茗
陌清茗 2020-12-01 05:53

Having read other people\'s questions I thought

window.onload=...

would answer my question. I have tried this but it executes the code the

9条回答
  •  遥遥无期
    2020-12-01 06:19

    Using window.onload will not work because it fires once the page is loaded, however images are not included in this definition of loaded.

    The general solution to this is the ImagesLoaded jQuery plugin.

    If you're keen on not using jQuery at all, you could at least try converting this plugin into pure Javascript. At 93 significant lines of code and with good commenting, it shouldn't be a hard task to accomplish.

提交回复
热议问题