Skip to main content
You are viewing Pre-Alpha documentation.
Vuetify0 Logo
Mode
Accessibility
Vuetify

useIntersectionObserver

A composable for detecting when elements enter or leave the viewport using the Intersection Observer API with automatic cleanup.

Usage

The useIntersectionObserver composable wraps the Intersection Observer API to detect when elements become visible in the viewport. It’s useful for lazy loading images, infinite scroll, entrance animations, and performance optimizations.

UseIntersectionObserver
<script setup lang="ts">
  import { useIntersectionObserver } from '@vuetify/v0'
  import { ref, useTemplateRef } from 'vue'

  const target = useTemplateRef('target')
  const isVisible = ref(false)

  useIntersectionObserver(target, (entries) => {
    isVisible.value = entries[0].isIntersecting
  }, {
    threshold: 0.5, // Trigger when 50% visible
    rootMargin: '0px'
  })
</script>

<template>
  <div>
    <div style="height: 100vh">Scroll down to see the element</div>
    <div ref="target" :class="{ visible: isVisible }">
      I'm {{ isVisible ? 'visible' : 'hidden' }}
    </div>
  </div>
</template>

Examples

Scroll Reveal

Cards that animate in when entering the viewport with intersection ratio tracking.

Scroll to reveal cards0/6 revealed
Scroll down to see the magic

Lazy Loading

Load images only when entering viewport

0%

Infinite Scroll

Fetch more content as users scroll

0%

Analytics

Track visibility for engagement metrics

0%

Animations

Trigger entrance animations on scroll

0%

Video Playback

Auto-play videos when visible

0%

Ad Viewability

Measure ad impressions accurately

0%
You've reached the end

Architecture

useIntersectionObserver wraps the native IntersectionObserver API with Vue reactivity:

Intersection Observer Hierarchy

Use controls to zoom and pan. Click outside or press Escape to close.

Intersection Observer Hierarchy

API Reference

The following API details are for the useIntersectionObserver composable.

Functions

useIntersectionObserver

(target: MaybeRef<Element>, callback: (entries: IntersectionObserverEntry[]) => void, options?: IntersectionObserverOptions) => UseIntersectionObserverReturn

A composable that uses the Intersection Observer API to detect when an element is visible in the viewport.

useElementIntersection

(target: MaybeRef<Element>, options?: IntersectionObserverOptions) => UseElementIntersectionReturn

A convenience composable that uses the Intersection Observer API to detect when an element is visible in the viewport.

Options

immediate

boolean

once

boolean

root

Element

threshold

number | number[]

Properties

isActive

Readonly<Ref<boolean, boolean>>

Whether the observer is currently active (created and observing)

isIntersecting

Readonly<Ref<boolean, boolean>>

Whether the target element is currently intersecting with the viewport

isPaused

Readonly<Ref<boolean, boolean>>

Whether the observer is currently paused

Methods

pause

() => void

Pause observation (disconnects observer but keeps it alive)

resume

() => void

Resume observation

stop

() => void

Stop observation and clean up (destroys observer)

Was this page helpful?

© 2016-1970 Vuetify, LLC
Ctrl+/