How to set up progress bar timing? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to set up progress bar timing?

More specific, i want to make the bar fully loaded when the page is loaded, any way?

25th Dec 2018, 12:48 AM
Jingga Sona
Jingga Sona - avatar
4 Answers
+ 7
First thing that appear in my mind is store the number of image you want to load like. var imgnum = document.getElementsByTagName("img").length Then use that value as max for the progress bar. Also create a variable for our counter. var imgloaded = 0; Then set up an onload listener to each image where it'll add imgloaded by 1. for(let i = 0; i<imgnum ;i++){ document.getElementsByTagName("img")[i].onload = ()=>{ imgloaded++ //Update progressbar } }
25th Dec 2018, 1:08 AM
Taste
Taste - avatar
+ 2
But the progress bar wont show if the page havent loaded yet. Did you mean wait for resource like image to load first ?
25th Dec 2018, 12:57 AM
Taste
Taste - avatar
+ 2
Yes, that was i meant😅
25th Dec 2018, 12:59 AM
Jingga Sona
Jingga Sona - avatar
+ 2
Wow Taste! Its amazing! Thanks👍
25th Dec 2018, 1:17 AM
Jingga Sona
Jingga Sona - avatar