Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
HTML + JavaScript : Add class to documentElement immediately then remove it 1 sec after window loaded.
<html>
<head>
<script>document.documentElement.className += "loading";</script>
</head>
<body>
<script>
(function () {
'use strict';
function removeTheClass() {
var rootElement = document.documentElement;
if (rootElement.classList.contains('loading')) {
setTimeout(function () {
rootElement.classList.remove('loading');
}, 1000);
}
}
window.onload = removeTheClass();
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment