Last active
October 22, 2024 04:39
-
-
Save jamesgathu/f4912009901ab0b33faef18fc2981f2b to your computer and use it in GitHub Desktop.
Simple page pre-loader using html, css and js
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
<!DOCTYPE> | |
<html lang='en'> | |
<head> | |
<title> Loader example </title> | |
<style> | |
.loading-gif { | |
max-width: 500px; | |
} | |
.pre-loader { | |
position: fixed; | |
z-index: 100; /** make sure this is the highest value compared to all other divs **/ | |
top: 0; | |
left: 0; | |
background: #191f26; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
height: 100%; | |
width: 100%; | |
} | |
.pre-loader.hidden { | |
animation: fadeOut 2s; /** change to 1s */ | |
animation-fill-mode: forwards; | |
} | |
@keyframes fadeOut { | |
100% { | |
opacity: 0; | |
visibility: hidden; | |
} | |
} | |
</style> | |
</head> | |
<body> | |
<!--- Your content goes here --> | |
<p>Page content</p> | |
<div class='pre-loader'> | |
<img class='loading-gif' alt='loading' src="https://media0.giphy.com/media/11FuEnXyGsXFba/source.gif"/> | |
</div> | |
<!-- js to hide preloader loading is done --> | |
<script type='text/javascript'> | |
window.addEventListener('load', function () { | |
document.querySelector('.pre-loader').className += ' hidden'; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment