I have a JS code that takes some time to execute, so I wanted to show loader till the code is executed. What I have did so far is like
$(".loader-block").addClass("show");
// simulate a 5 second delay
setTimeout(() => { $(".loader-block").removeClass("show"); }, 5000);
.loader-block {
width: 417px;
height: 100%;
background: #eee;
position: absolute;
display: none;
top: 0;
left: 0;
z-index: 9;
}
.loader-block.show {
display: block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="loader-block">
<img src="/img/new-loader.gif" alt="Goodness never stops to wait for you">
</div>
JS CODE
$(".loader-block").addClass("show");
......
.... Some JS Code
......
$(".loader-block").removeClass("show");
HTML
<div class="loader-block">
<img src="/img/new-loader.gif">
</div>
CSS
.loader-block {
width: 417px;
height: 100%;
background: #eee;
position: absolute;
display: none;
top: 0;
left: 0;
z-index: 9;
}
.loader-block.show {
display: block;
}
I confirmed that class is been applied to element and gets removed after execution, but the display:block
css (which is in show
class) is not reflected while the show
class is applied. In short I feel this is something related to UI repaint. Any suggestions would be much appreciated.
I even checked applying display:block
css directly to element, I see the css is applied but result is not rendered.