Skip to content

useBoosterComponentObserver

Types

ts
declare function useBoosterComponentObserver(options?: ObservableOptions): {
    el: Ref<HTMLElement | undefined, HTMLElement | undefined>;
    inView: Ref<boolean, boolean>;
};

declare interface ObservableOptions = {
  root?: HTMLElement;
  rootMargin?: string;
  threshold?: number | number[];
  trackVisibility?: boolean;
  delay?: number;
};

Options

PropertyDescriptionDefault Value
rootMDN rootundefined
rootMarginMDN rootMargin'0px'
thresholdMDN threshold[0]
trackVisibilityMDN trackVisibilityfalse
delayMDN delay0

Return

PropertyDescription
elComponent ref for tag referencing.
inViewReference that indicates whether referenced element is visible.

Example

html
<template>
  <div ref="target" :class="{visible: inView}">

  </div>
</template>

<script setup>
const { el: target, inView } = useBoosterComponentObserver({
  trackVisibility: true,
  delay: 350
});
</script>