|
|
@@ -1,13 +1,11 @@
|
|
|
<template>
|
|
|
- <!--suppress VueUnrecognizedDirective -->
|
|
|
<div
|
|
|
:id="id"
|
|
|
ref="section"
|
|
|
- v-intersect="onIntersect"
|
|
|
+ v-scroll="onScroll"
|
|
|
>
|
|
|
<slot/>
|
|
|
</div>
|
|
|
-
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
@@ -30,36 +28,31 @@
|
|
|
|
|
|
layoutStore.setIsAnchoredSectionOnScreen(props.id, false)
|
|
|
|
|
|
- const onIntersect = (e: boolean) => {
|
|
|
- layoutStore.setIsAnchoredSectionOnScreen(props.id, e)
|
|
|
- }
|
|
|
+ const top: Ref<number | null> = ref(null)
|
|
|
+ const bottom: Ref<number | null> = ref(null)
|
|
|
+
|
|
|
+ onMounted(() => {
|
|
|
+ top.value = section.value!.offsetTop
|
|
|
+ bottom.value = section.value!.offsetTop + section.value!.offsetHeight
|
|
|
+ })
|
|
|
+
|
|
|
|
|
|
- // TODO: supprimer si pas nécessaire, je conserve au cas où il faudrait un
|
|
|
- // fonctionnement plus fin qu'un simple intersect
|
|
|
- // const top: Ref<number | null> = ref(null)
|
|
|
- // const bottom: Ref<number | null> = ref(null)
|
|
|
- //
|
|
|
- // onMounted(() => {
|
|
|
- // top.value = section.value!.offsetTop
|
|
|
- // bottom.value = section.value!.offsetTop + section.value!.offsetHeight
|
|
|
- // })
|
|
|
- //
|
|
|
- // const onScroll = (e: any) => {
|
|
|
- // if (top.value === null || bottom.value === null) {
|
|
|
- // return
|
|
|
- // }
|
|
|
- //
|
|
|
- // const scroll: number = e.target.scrollingElement.scrollTop
|
|
|
- //
|
|
|
- // const active = scroll > top.value && scroll < bottom.value
|
|
|
- //
|
|
|
- // if (active !== layoutStore.isAnchoredSectionOnScreen[props.id]) {
|
|
|
- // layoutStore.setIsAnchoredSectionOnScreen(
|
|
|
- // props.id,
|
|
|
- // active
|
|
|
- // )
|
|
|
- // }
|
|
|
- // }
|
|
|
+ const onScroll = (e: any) => {
|
|
|
+ if (top.value === null || bottom.value === null) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const screenVerticalCenter = document.documentElement.scrollTop + window.innerHeight / 2
|
|
|
+
|
|
|
+ const active = screenVerticalCenter > top.value && screenVerticalCenter < bottom.value
|
|
|
+
|
|
|
+ if (active !== layoutStore.isAnchoredSectionOnScreen[props.id]) {
|
|
|
+ layoutStore.setIsAnchoredSectionOnScreen(
|
|
|
+ props.id,
|
|
|
+ active
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|