How to add loader in the website in a few seconds 😎

atulcodex profile image Atul Prajapati ・1 min read

Magic of this few lines of JS code 🐝

let spinnerWrapper = document.querySelector('.spinner-wrapper');

window.addEventListener('load', function(){
spinnerWrapper.style.display= 'none';


Editor guide

Add this to re-enable the loading layer on page exit(ing):

window.addEventListener('beforeunload', function() {
    spinnerWrapper.style.display = "";

Kayaknya nggak perlu deh


Coba dulu. Terus klik salah satu tautan di halaman. Efek loading bakal muncul lagi.

Eh iya juga ya

Sorry bro but I can't understand your language πŸ™„ but thanks for commenting

Hehehehehe. I so sorry. I use Indonesian because, Taufik is Indonesian. Hehehehehe

taufik_nurrohman image

Cool πŸ‘πŸŽ‰πŸ’


I noticed in some cases you used .spinner:before and .spinner:after instead of .spinner::before and .spinner::after for the pseudo-elements. I think you need to use double colons since a single colon is reserved for pseudo-classes, like :focus or :hover.


Okay hmm interesting 😲 I will try thanks for your opinion 🌷


The logic is correct Aleksandr, but in practice this is rarely needed. Most people just use : for everything. I've never seen a situation where using ::before worked and :before didn't.


You are right brother πŸ‘‹


I had no idea that was so simple without a framework!


Really love this one.
One question is it is compulsory to set the /stimulate page content/ code ...?


No it's your body content I have added it for page content put here your page code. Any other questions bro?


Ohk bro thanks for ur reply

I love to do that ✌️