I'm using a loading screen to cover my site (http://advancedriderwear.com/index.html) whilst it loads which is great, except it reaches 100% before my landing screen is loaded, and therefore the user still see's images loading, which isnt good!. ' Here's the code I'm using:
;
(function() {
function id(v) {
return document.getElementById(v);
}
function loadbar() {
var ovrl = id("overlayLoad"),
prog = id("progress"),
stat = id("progstat"),
img = document.images,
c = 0,
tot = img.length;
if (tot == 0) return doneLoading();
function imgLoaded() {
c += 1;
var perc = ((100 / tot * c) << 0) + "%";
prog.style.width = perc;
stat.innerHTML = "Loading " + perc;
if (c === tot) return doneLoading();
}
function doneLoading() {
ovrl.style.opacity = 0;
setTimeout(function() {
ovrl.style.display = "none";
}, 5000);
}
for (var i = 0; i < tot; i++) {
var tImg = new Image();
tImg.onload = imgLoaded;
tImg.onerror = imgLoaded;
tImg.src = img[i].src;
}
}
document.addEventListener('DOMContentLoaded', loadbar, false);
}());
Is this a correct method or is there an alternative to ensure the page is fully loaded before the main site is displayed.
The Loading screen is styled using:
.LoaderIcon{
margin: auto;
display: flex;
align-items: center;
justify-content: center;
padding-top: 5%;
}
#overlayLoad{
position:fixed;
z-index:99999;
top:0;
left:0;
bottom:0;
right:0;
background:rgba(0,0,0,1);
transition: 1s 0.4s;
display: block;
}
#progress{
height:2px;
background:#fff;
position:absolute;
width:0;
top:50%;
font-family: Magistral;
font-size: 1.5em;
}
#progstat{
letter-spacing: 3px;
position:absolute;
top:50%;
margin-top:-40px;
width:100%;
text-align:center;
color:#fff;
font-family: 'UniversLTW01-59UltCondensed';
font-size: 1.5em;
}