Skip to content

Instantly share code, notes, and snippets.

@TravisMullen
Created March 30, 2017 13:11
Show Gist options
  • Save TravisMullen/59b1ae4ccb4f4517c34db67ef4a862ab to your computer and use it in GitHub Desktop.
Save TravisMullen/59b1ae4ccb4f4517c34db67ef4a862ab to your computer and use it in GitHub Desktop.
Making Animations Wait
// wait for document
document.body.className += " js-loading";
window.addEventListener("load", removeLoadingClass, false);
function removeLoadingClass() {
document.body.className = document.body.className.replace("js-loading","");
}
// wait for image
// Adjust the "querySelector" value to target your image
var img = document.querySelector("img");
document.body.className += " js-loading";
img.addEventListener("load", removeLoadingClass);
function removeLoadingClass() {
document.body.className = document.body.className.replace("js-loading","");
}
/*
.js-loading *,
.js-loading *:before,
.js-loading *:after {
animation-play-state: paused !important;
}
*/
// ref: https://css-tricks.com/making-animations-wait/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment