[removed] Know when an image is fully loaded

前端 未结 7 1067
旧巷少年郎
旧巷少年郎 2020-11-30 02:42

If I have a beacon:


I want a method to be called once the beacon request finishes. Somethin

相关标签:
7条回答
  • 2020-11-30 03:24

    You can do it easily in two way.lets see the ways:

    1.Using onload attribute in img tag:

    <img onload="alert('loaded');" src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png">
    

    This will trigger alert just after the photo is finished loading.

    2.Using EventListener in JavaScript:

    document.getElementsByTagName("img");.addEventListener("load", function loaded(){
      //any code you may need
      }); 
    

    These code goes in your external js file or internal script tag.

    You can do this for every individual img tag using class and id attribute.

    0 讨论(0)
提交回复
热议问题