Skip to content

Instantly share code, notes, and snippets.

@mauricerenck
Last active January 17, 2020 15:36
Show Gist options
  • Save mauricerenck/d0e06c860034029a185b259168717a1d to your computer and use it in GitHub Desktop.
Save mauricerenck/d0e06c860034029a185b259168717a1d to your computer and use it in GitHub Desktop.
<!-- right after <body> -->
<div class="fader"></div>
<script>
const fader = document.querySelector('.fader')
fader.classList.add('fade');
</script>
<!-- before </body> -->
<script>
// this block is optional
/* document.addEventListener("DOMContentLoaded", function(e) {
fader.classList.add('fading');
setTimeout(() => {
fader.classList.remove('fading');
fader.classList.remove('fade');
}, 500);
});
*/
window.addEventListener("beforeunload", () => {
fader.classList.add('fade');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment