Skip to content

Instantly share code, notes, and snippets.

@yspreen
Created May 28, 2021 16:01
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 yspreen/0a364f9fbd4df07f8bf1fd80b1236402 to your computer and use it in GitHub Desktop.
Save yspreen/0a364f9fbd4df07f8bf1fd80b1236402 to your computer and use it in GitHub Desktop.
<script>
function updateAnimations() {
$(".video").each(function () {
if (
this.getBoundingClientRect().top <= window.innerHeight &&
this.getBoundingClientRect().bottom >= 0
) {
this.classList.add("scrolled-in");
this.classList.remove("scrolled-out");
} else {
this.classList.remove("scrolled-in");
this.classList.add("scrolled-out");
}
});
}
function main() {
$(document).scroll(function () {
updateAnimations();
});
$(".video").each(function () {
this.onload = updateAnimations;
});
updateAnimations();
}
$(main);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment