Skip to content
24 / 27

Как использовать useIntersectionObserver из VueUse?

useIntersectionObserver оборачивает нативный IntersectionObserver в реактивный composable. Передаёшь ref на элемент и колбэк -- получаешь отслеживание видимости элемента без ручной работы с API браузера.

JavaScript
import { useIntersectionObserver } from '@vueuse/core'
import { ref } from 'vue'

const target = ref(null)
const isVisible = ref(false)

useIntersectionObserver(target, ([{ isIntersecting }]) => {
    isVisible.value = isIntersecting
  })