Last active
June 6, 2019 16:18
-
-
Save ycmjason/ea93f9eb1c453a9e36a8536427c59695 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<div ref="container"> | |
<Card v-for="(card, i) of cards" ref="cards"> | |
<IntersectionObserver :getTarget="() => this.$refs.cards[i]" @intersect="liftCard" @disintersect="unliftCard" /> | |
... | |
</Card> | |
</div> | |
<!-- vs --> | |
<div ref="container"> | |
<IntersectionObserver :getTarget="() => this.$refs.cards" @intersect="liftOrUnliftCard" /> | |
<Card v-for="(card, i) of cards"> | |
... | |
</Card> | |
</div> | |
<script> | |
export default { | |
methods: { | |
liftOrUnliftCard (entries) { | |
entries.filter(({ isIntersecting }) => isIntersecting).forEach(this.liftCard) | |
entries.filter(({ isIntersecting }) => !isIntersecting).forEach(this.unliftCard) | |
}, | |
liftCard () { /* lift the card */ }, | |
unliftCard () { /* unlift the card */ }, | |
}, | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment