I have a preloading page that shows a CSS animation before the webpage has been fully loaded in the client's browser. It works in Chrome, Firefox and Internet Explorer but it fails to work in Safari. Even the CSS commands do not work properly in Safari and I can't figure why!
When I open it in Safari, the first problem is that the animation doesn't work properly. I even added @-webkit-keyframes but it didn't change anything. But what is even weirder is that the javascript code doesn't work either. For example, even though I specify that body should no longer be scrolled, I can still scroll it down. I suppose it's a cross-browser issue with javascript, but I can't figure what it is exactly. Is it because I'm using the event "load"? Maybe Safari doesn't recognize it?
I wanted to rewrite the code using jQuery, but I couldn't find an equivalent for window.addEvenListener("load",callback()); in jQuery. The event listener .load() has been deprecated.
UPDATE: The problem seems to be that Safari doesn't properly execute overflow: hidden. Does anyone know any workaround for this problem?
Here's the MVC
document.body.style.overflow = "hidden";
setTimeout(() => {
window.addEventListener('load', loaded());
}, 5000);
function loaded(){
document.getElementById('loading').style.display = 'none';
document.body.style.overflowY = 'visible';
}
#loading {
display: block;
width: 100vw;
height: 100vh;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
background-color: white;
z-index: 10;
}
#flex_wrapper{
position: relative;
width: 100%;
top: calc(50% - 50px);
height: 50px;
display: flex;
align-items: center;
justify-content: center;
}
#loading_text{
width: 100%;
font-size: 1.2em;
font-weight: 400;
position: relative;
top: calc(50% - 30px);
height: 50px;
text-align: center;
line-height: 25px;
}
.loading_bar{
width: 8px;
height: 50px;
background-color: black;
margin: 0 5px;
border-radius: 10px;
animation: loading 1s infinite;
}
@keyframes loading{
0%{
height: 0px;
}
50%{
height: 50px;
}
100%{
height: 0px;
}
}
.loading_bar:nth-child(2){
animation-delay: 0.1s;
}
.loading_bar:nth-child(3){
animation-delay: 0.2s;
}
.loading_bar:nth-child(3){
animation-delay: 0.3s;
}
.loading_bar:nth-child(4){
animation-delay: 0.4s;
}
.loading_bar:nth-child(5){
animation-delay: 0.5s;
}
.loading_bar:nth-child(6){
animation-delay: 0.6s;
}
.loading_bar:nth-child(7){
animation-delay: 0.7s;
}
.loading_bar:nth-child(8){
animation-delay: 0.8s;
}
.loading_bar:nth-child(9){
animation-delay: 0.9s;
}
.loading_bar:nth-child(10){
animation-delay: 1s;
}
<div id="loading">
<div id="flex_wrapper">
<div class="loading_bar"></div>
<div class="loading_bar"></div>
<div class="loading_bar"></div>
<div class="loading_bar"></div>
<div class="loading_bar"></div>
<div class="loading_bar"></div>
<div class="loading_bar"></div>
<div class="loading_bar"></div>
<div class="loading_bar"></div>
<div class="loading_bar"></div>
</div>
<div id="loading_text">
Please wait<br> Loading...
</div>
</div>