bodanus7
bodanus7

Reputation: 29

How to add time to window.addEventListener

I'm creating a website loader and have the following code:

window.addEventListener('load', function load() {
                window.removeEventListener('load', load, false);               
                document.body.classList.remove('js-loading');
            },
               false);

Thanks to this I'm creating a CSS animation with .js-loading class, and when the page is loaded this class is removed. To have a smooth finished animation I need add some delay time after that this class will disappear. (website load time + additional delay) Could you help me?

Upvotes: 0

Views: 1424

Answers (1)

Jaydip Jadhav
Jaydip Jadhav

Reputation: 12309

SetTimeout:

window.addEventListener('load', function load() {
     window.removeEventListener('load', load, false);               
     setTimeout(function(){document.body.classList.remove('js-loading');},2000);

},false);

Upvotes: 1

Related Questions