Your code is correct. After loading the object window
the event will be triggered load
which will execute the method .fadeOut()
in the element. Only you are specifying that the fade out will last 2 seconds (2000 milliseconds), but it will run right after the load
.
By default fadeOut lasts 400 milliseconds if you leave the duration blank, but you can specify a shorter duration using "fast", which will be 200 milliseconds:
$('.preload-content').fadeOut("fast");
Or else a lower value to get faster:
$('.preload-content').fadeOut(100);
Or you can use the method .hide()
which hides the widget with no effect. The direction between .hide()
and .fadeOut()
is that one hides the element without any effect and the other the same thing, but with a fading effect before.
A hint would also be to remove the DOM element right away, since it only actually serves at the top of the page. Then you use the .fadeOut()
for that reason:
$('.preload-content').fadeOut(100, function(){
$(this).remove();
});
So the element will fade by 1-tenth of a second and then be removed from the page instead of just hidden. See how it looks:
$('.preload-content').fadeOut(100, function(){
$(this).remove();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="preload-content">Carregando</div>
You can try studying about Prefetching, preloading, prebrowsing. https://css-tricks.com/prefetching-preloading-prebrowsing/
– Ikaro Sales
You want the
.preload-content
disappear when the page loads?– g-otn
Extly G.Otani P.
– Robson Freitas
Your question is unclear, not just withdraw the fadeOut()? The page is loaded and still gets the Preload for a while is this?
– LeAndrade