mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-03-14 14:16:15 +01:00
39 lines
937 B
Vue
39 lines
937 B
Vue
|
<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>
|