I'm having trouble finding any good information on how to make a javascript(or jquery) progress bar WITH text that tells you the percentage.
I don't want a plug in, I just want to know how it works so that I can adapt it to what I need. How do you preload images and get a variable for the number of images that are preloaded. Also, how do you change html/css and-or call a function, based on the number of images that are loaded already?
<img>
elements have anonload
event that fires once the image has fully loaded. Therefore, in js you can keep track of the number of images that have loaded vs the number remaining using this event.Images also have corresponding
onerror
andonabort
events that fire when the image fails to load or the download have been aborted (by the user pressing the 'x' button). You also need to keep track of them along with theonload
event to keep track of image loading properly.Additional answer:
A simple example in pure js:
The example above doesn't handle
onerror
oronabort
for clarity but real world code should take care of them as well.What about using something below:
JSFIDDLE
You might also want to try HTML5 progress element:
http://www.html5tutorial.info/html5-progress.php