Skip to content

Instantly share code, notes, and snippets.

@ItangSanjana
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ItangSanjana/edadf9f0749413eae6b0 to your computer and use it in GitHub Desktop.
Save ItangSanjana/edadf9f0749413eae6b0 to your computer and use it in GitHub Desktop.
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