If you just need to "hide" your site content before load
is triggered, you can use a class with this property that you are inserting directly into the DOM, / p>
.hide { display: none }
Content to be "hidden" while the page loads may initially have this class. Just remove it when load
is fired.
ps: I put an image to the 'load' to be triggered on a first load.
var loading = document.querySelector('div'),
content = document.querySelector('main');
window.onload = function() {
loading.classList.add('hide'); // esconde o 'carregando'.
content.classList.remove('hide'); // mostra o conteúdo do site.
};
.hide, img { display: none }
<div>
<p>carregando...</p>
</div>
<main class='hide'>
<img src='http://i.stack.imgur.com/uoKIw.jpg' />
conteúdo do site.
</main>
In the example above I used classList
but I already added that not all browsers have this feature implemented. Internet Explorer < 10 and Opera Mini 5 do not support classList
- view browsers that support . However in this answer (en) there are possible solutions that you can use.
If you want to display a progress bar as the site loads (showing the percentage), I suggest using PACE / a> for this.