Created
July 14, 2021 17:32
-
-
Save mattmaribojoc/0c58749470dc7304b76bc54db2f423c6 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
<template> | |
<p> Is target visible? {{ targetIsVisible }} </p> | |
<div class="container"> | |
<div class="target" ref="target"> | |
<h1>Hello world</h1> | |
</div> | |
</div> | |
</template> | |
<script> | |
import { ref } from 'vue' | |
import { useIntersectionObserver } from '@vueuse/core' | |
export default { | |
setup() { | |
const target = ref(null) | |
const targetIsVisible = ref(false) | |
const { stop } = useIntersectionObserver( | |
target, | |
([{ isIntersecting }], observerElement) => { | |
targetIsVisible.value = isIntersecting | |
}, | |
) | |
return { | |
target, | |
targetIsVisible, | |
} | |
}, | |
} | |
</script> | |
<style scoped> | |
.container { | |
width: 80%; | |
margin: 0 auto; | |
background-color: #fafafa; | |
max-height: 300px; | |
overflow: scroll; | |
} | |
.target { | |
margin-top: 500px; | |
background-color: #1abc9c; | |
color: white; | |
padding: 20px; | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment