Last active
January 9, 2021 12:04
-
-
Save ArthurBeaulieu/7f063ece10c4779f688d1dac1af3fa06 to your computer and use it in GitHub Desktop.
A quick loading overlay to be used when switching views or during heavy procssing.
This file contains hidden or 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
// To use as your page loading: | |
// Best way is to embed in your HTML a DIV.overlay, without the hidden class | |
// This way, your page is loaded with the overlay on | |
// Do your initialization stuff, then just stop the loading, voilà! | |
// Attach to window to make it globally available in your runtime | |
window.overlay = document.querySelector('#overlay'); | |
// ... Or, built an overlay DOM element when required | |
window.overlay = document.createElement('DIV'); | |
window.overlay.className = 'overlay hidden'; | |
document.body.appendChild(window.overlay); | |
// Use this line to start the loading and add the overlay | |
requestAnimationFrame(() => window.overlay.classList.remove('hidden')); | |
// Use this one to stop the loading and remove the overlay | |
requestAnimationFrame(() => window.overlay.classList.remove('hidden')); |
This file contains hidden or 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
@keyframes rotate { | |
0% { | |
transform: perspective(120px) rotateX(0deg) rotateY(0deg); | |
} 50% { | |
transform: perspective(120px) rotateX(-180.1deg) rotateY(0deg); | |
} 100% { | |
transform: perspective(120px) rotateX(-180deg) rotateY(-179.9deg); | |
} | |
} | |
.overlay { | |
background-color: rgba(0, 0, 0, .7); | |
height: 100%; | |
left: 0; | |
position: absolute; | |
top: 0; | |
width: 100%; | |
z-index: 9999; | |
&.hidden { | |
display: none; | |
} | |
&::before { | |
content: ''; | |
background-color: rgb(55, 195, 64); | |
border-radius: 5px; | |
height: 50px; | |
left: calc(50% - 25px); | |
position: absolute; | |
top: 50%; | |
width: 50px; | |
animation: rotatePlane 1.2s infinite ease-in-out; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment