Skip to content

Instantly share code, notes, and snippets.

@mattmaribojoc
Created July 14, 2021 17:32
Show Gist options
  • Save mattmaribojoc/0c58749470dc7304b76bc54db2f423c6 to your computer and use it in GitHub Desktop.
Save mattmaribojoc/0c58749470dc7304b76bc54db2f423c6 to your computer and use it in GitHub Desktop.
<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