WASAPhoto/webui/src/components/IntersectionObserver.vue

39 lines
937 B
Vue
Raw Normal View History

2022-12-23 01:00:51 +01:00
<script>
export default {
name: 'IntersectionObserver',
props: {
sentinalName: {
type: String,
required: true,
},
},
data() {
return {
isIntersectingElement: false,
}
},
watch: {
isIntersectingElement: function (value) {
if (!value) return
this.$emit('on-intersection-element')
},
},
mounted() {
const sentinal = this.$refs[this.sentinalName]
const handler = (entries) => {
if (entries[0].isIntersecting) {
this.isIntersectingElement = true
}
else {
this.isIntersectingElement = false
}
}
const observer = new window.IntersectionObserver(handler)
observer.observe(sentinal)
},
}
</script>
<template>
<div :ref="sentinalName" class="w-full h-px relative" />
</template>