The Logic :
The basic requirement for this script is the knowledge of how many images exist. So for that purpose we have to count the number of images in the document. In this simple preloader, we will consider only the images in img tags. Jquery provides a powerful function for counting these or any other tags. We just have to say $('img').length() and we get the total count of the given element. Next we find the percentage each image contributes to the total.
Once we have the count we have to find the sources of these images so that they can be loaded one by one. While loading the image we also assign event trigger to the image so that it notifies us that it is loaded and we can proceed with incrementing the progressbar by the smallest percentage.
Once the percentage reaches 100% we can fade out the overlay screen.
The code :
So this was a simple preloader with progress bar which took all the html images into consideration. In our next post we will make our script a bit complex by taking the css images into consideration.
Have a nice day :)
No comments:
Post a Comment