Last active
August 1, 2024 17:12
-
-
Save nichoth/646e7708f3e438e8318846f369fa1ca2 to your computer and use it in GitHub Desktop.
FOUC — flash of unstyled content
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
// see https://stackoverflow.com/questions/3221561/eliminate-flash-of-unstyled-content | |
// | |
// The problem with using a css style to initially hide some page | |
// elements, and then using javascript to change the style back to | |
// visible after page load, is that people who don't have javascript | |
// enabled will never get to see those elements. | |
// | |
// so, use javascript to both initially hide as well as redisplay | |
// those elements after page load | |
// | |
/** | |
* FOUC prevention | |
*/ | |
document.body.style.opacity = 0 | |
document.body.style.visiblity = 'hidden' | |
window.addEventListener('load', () => { | |
document.body.style.visibility = 'visible' | |
document.body.style.opacity = 1 | |
}) | |
// + some CSS for transition | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment