Skip to content

Instantly share code, notes, and snippets.

@cp-sumi-k
Last active February 8, 2022 12:22
Show Gist options
  • Save cp-sumi-k/cd60eb35f8bc0d742bb8d20d6e14ba68 to your computer and use it in GitHub Desktop.
Save cp-sumi-k/cd60eb35f8bc0d742bb8d20d6e14ba68 to your computer and use it in GitHub Desktop.
<script>
export default {
data() {
return {
grid1: [...],
grid2: [...],
lastScrollY: 0,
gridAnimation: "",
};
},
methods: {
scrollHandler() {
let diff = window.scrollY - this.lastScrollY;
//scroll up
if (diff < 0) {
this.gridAnimation = "grid-animation-reverse-running";
} else {
this.gridAnimation = "";
}
this.lastScrollY = window.scrollY;
},
},
mounted() {
window.addEventListener("scroll", this.scrollHandler);
},
unmounted() {
window.removeEventListener("scroll", this.scrollHandler);
},
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment