4
Guys I’m mounting the loading system using Jquery.
And they consist of a div that covers the entire tala in the browser and that when all elements of the page are loaded, Jquery hides the div.
The system is working very well, however it is displayed even when the page is very light and fast.
I wanted to know how to make it appear only if the page takes more than 2 seconds to load.
Follow the load code.
$(window).load(function() {
$(".se-pre-con").fadeOut("fast");
});
.se-pre-con {
position: fixed;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
z-index: 9999;
background: url(https://media0.giphy.com/media/3oEjI6SIIHBdRxXI40/200_s.gif) center no-repeat #FFFFFF;
}
.se-pre-con p {
width: 160px;
height: 15px;
position: absolute;
top: 70%;
left: 48%;
margin-top: -70px;
margin-left: -48px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<!-- Loading -->
<div class="se-pre-con"><p>PROCESSANDO DADOS</p></div>
blablablablablalba<br>blablablablablalba<br>blablablablablalba<br>blablablablablalba<br>blablablablablalba<br>blablablablablalba<br>blablablablablalba<br>blablablablablalba<br>
I tried it here and it didn’t work. the loading didn’t appear on a page that takes a long time to load
– Hugo Borges
and in the log do not present the
console.log('demorou para carregar');
?– Neuber Oliveira
This is not appearing the
console.log('demorou para carregar');
. appears to just the finished.– Hugo Borges
and how are you testing how long the page takes? And what do you consider loaded? Why if it is not falling into the settimeout if it is why the
$(window).load()
this being called before.– Neuber Oliveira
Well not even running your code here in the stack it shows how late you realized? And I’m trying the code on a page that selects in the comic book and assembles a page in html. It takes about 4.23ms to load, because it’s a lot of BD records
– Hugo Borges
Exactly, as there is no processing here it does not take 2 seconds and therefore does not display, as expected, the log that took, I edited the answer and commented the
var loaded = false;
. Voce will see that the log that ended appears and then the loading and the log message that took long appears. that’s why when you enter thesetTimeout()
He doesn’t know he’s finished loading, because I commented on the line– Neuber Oliveira
Well I noticed that only displays the loading after the page loads, so the seconds are commenting to count only after the page loads.
– Hugo Borges
I managed to make everything work by placing inside the <head> tag has how to make it work by placing at the end of the body?
– Hugo Borges