AnchoredSection.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <!--suppress VueUnrecognizedDirective -->
  3. <div
  4. :id="id"
  5. ref="section"
  6. v-intersect="onIntersect"
  7. >
  8. <slot/>
  9. </div>
  10. </template>
  11. <script setup lang="ts">
  12. import { useLayoutStore } from "~/stores/layoutStore";
  13. const layoutStore = useLayoutStore()
  14. const props = defineProps({
  15. id: {
  16. type: String,
  17. required: true
  18. }
  19. })
  20. if (!props.id) {
  21. throw new Error("Anchor's id is missing")
  22. }
  23. const section: Ref<HTMLElement | null> = ref(null)
  24. layoutStore.setIsAnchoredSectionOnScreen(props.id, false)
  25. const onIntersect = (e: boolean) => {
  26. layoutStore.setIsAnchoredSectionOnScreen(props.id, e)
  27. }
  28. // TODO: supprimer si pas nécessaire, je conserve au cas où il faudrait un
  29. // fonctionnement plus fin qu'un simple intersect
  30. // const top: Ref<number | null> = ref(null)
  31. // const bottom: Ref<number | null> = ref(null)
  32. //
  33. // onMounted(() => {
  34. // top.value = section.value!.offsetTop
  35. // bottom.value = section.value!.offsetTop + section.value!.offsetHeight
  36. // })
  37. //
  38. // const onScroll = (e: any) => {
  39. // if (top.value === null || bottom.value === null) {
  40. // return
  41. // }
  42. //
  43. // const scroll: number = e.target.scrollingElement.scrollTop
  44. //
  45. // const active = scroll > top.value && scroll < bottom.value
  46. //
  47. // if (active !== layoutStore.isAnchoredSectionOnScreen[props.id]) {
  48. // layoutStore.setIsAnchoredSectionOnScreen(
  49. // props.id,
  50. // active
  51. // )
  52. // }
  53. // }
  54. </script>
  55. <style scoped>
  56. </style>