简体   繁体   中英

How to know when you have received an image in the browser?

Let me explain myself as my question title may be a tad random. My website has a good few images, as such I want to have say a loading bar that as my browser receives and image it moves the bar x pixels to the right. Now the css behind it all isn't to bad. The problem I'm having is with JavaScript how one would determine when the how image has been obtained in the browser? So when all the images have loaded I can simply just show a neat page with out the user seeing all these images slowly download on their screen. Something similar to the following site:

Link

Or even I'm completely wrong here? How is the above link achieving this? Any tutorials would be a great help. As I tried googling "HTML Loading pages" This really is my first time doing this ever.

If you are using jQuery then please use load event on image selector like

 $(function(){
   $("#image").bind("load", function(E){
     alert("Load");
   });
 });

Or you can also use onload JavaScript event

document.getElementById('image').onload = function(){alert("Load");}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM