Created
November 30, 2021 14:28
-
-
Save alessandroalessio/9718c2e4cfa6c31b013eb2e27bb1cc8d to your computer and use it in GitHub Desktop.
Vanilla Javascript Page Loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Page Loader | |
document.addEventListener('readystatechange', function(event) { | |
if (document.readyState === "complete") { | |
setTimeout(function(){ | |
document.getElementById('loader').classList.add('hide'); | |
}, 1000); | |
} | |
}); | |
window.addEventListener( 'beforeunload', function( event ) { | |
event.preventDefault(); | |
document.getElementById('loader').classList.remove('hide'); | |
console.log(event); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment