Created
January 14, 2020 20:56
-
-
Save jeangontijo/0361b3ed66ff800e54685bf080dedc29 to your computer and use it in GitHub Desktop.
Keyframe Animation to Scroll
This file contains 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
:root * { | |
/* Pause the animation */ | |
animation-play-state: paused; | |
/* Bind the animation to scroll */ | |
animation-delay: calc(var(--scroll) * -1s); | |
/* These last 2 properites clean up overshoot weirdness */ | |
animation-iteration-count: 1; | |
animation-fill-mode: both; | |
} | |
document.addEventListener( 'DOMContentLoaded', function () { | |
var root = document.body.style; | |
console.log(root); | |
// Initialize variables | |
root.setProperty('--scroll',window.pageYOffset / (document.body.offsetHeight - window.innerHeight)); | |
// Scroll events | |
window.addEventListener('scroll',scroll,false); | |
function scroll() { | |
root.setProperty('--scroll',window.pageYOffset / (document.body.offsetHeight - window.innerHeight)); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment