Pulled ALL skills from 15 source repositories: - anthropics/skills: 16 (docs, design, MCP, testing) - obra/superpowers: 14 (TDD, debugging, agents, planning) - coreyhaines31/marketingskills: 25 (marketing, CRO, SEO, growth) - better-auth/skills: 5 (auth patterns) - vercel-labs/agent-skills: 5 (React, design, Vercel) - antfu/skills: 16 (Vue, Vite, Vitest, pnpm, Turborepo) - Plus 13 individual skills from various repos Mosaic Stack is not limited to coding — the Orchestrator and subagents serve coding, business, design, marketing, writing, logistics, analysis, and more. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
119 lines
2.6 KiB
Markdown
119 lines
2.6 KiB
Markdown
---
|
|
category: Elements
|
|
---
|
|
|
|
# useIntersectionObserver
|
|
|
|
Detects that a target element's visibility.
|
|
|
|
## Usage
|
|
|
|
```vue
|
|
<script setup lang="ts">
|
|
import { useIntersectionObserver } from '@vueuse/core'
|
|
import { shallowRef, useTemplateRef } from 'vue'
|
|
|
|
const target = useTemplateRef('target')
|
|
const targetIsVisible = shallowRef(false)
|
|
|
|
const { stop } = useIntersectionObserver(
|
|
target,
|
|
([entry], observerElement) => {
|
|
targetIsVisible.value = entry?.isIntersecting || false
|
|
},
|
|
)
|
|
</script>
|
|
|
|
<template>
|
|
<div ref="target">
|
|
<h1>Hello world</h1>
|
|
</div>
|
|
</template>
|
|
```
|
|
|
|
## Directive Usage
|
|
|
|
```vue
|
|
<script setup lang="ts">
|
|
import { vIntersectionObserver } from '@vueuse/components'
|
|
import { shallowRef, useTemplateRef } from 'vue'
|
|
|
|
const root = useTemplateRef('root')
|
|
|
|
const isVisible = shallowRef(false)
|
|
|
|
function onIntersectionObserver([entry]: IntersectionObserverEntry[]) {
|
|
isVisible.value = entry?.isIntersecting || false
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<p>
|
|
Scroll me down!
|
|
</p>
|
|
<div v-intersection-observer="onIntersectionObserver">
|
|
<p>Hello world!</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- with options -->
|
|
<div ref="root">
|
|
<p>
|
|
Scroll me down!
|
|
</p>
|
|
<div v-intersection-observer="[onIntersectionObserver, { root }]">
|
|
<p>Hello world!</p>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
```
|
|
|
|
[IntersectionObserver MDN](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/IntersectionObserver)
|
|
|
|
## Type Declarations
|
|
|
|
```ts
|
|
export interface UseIntersectionObserverOptions extends ConfigurableWindow {
|
|
/**
|
|
* Start the IntersectionObserver immediately on creation
|
|
*
|
|
* @default true
|
|
*/
|
|
immediate?: boolean
|
|
/**
|
|
* The Element or Document whose bounds are used as the bounding box when testing for intersection.
|
|
*/
|
|
root?: MaybeComputedElementRef | Document
|
|
/**
|
|
* A string which specifies a set of offsets to add to the root's bounding_box when calculating intersections.
|
|
*/
|
|
rootMargin?: string
|
|
/**
|
|
* Either a single number or an array of numbers between 0.0 and 1.
|
|
* @default 0
|
|
*/
|
|
threshold?: number | number[]
|
|
}
|
|
export interface UseIntersectionObserverReturn extends Pausable {
|
|
isSupported: ComputedRef<boolean>
|
|
stop: () => void
|
|
}
|
|
/**
|
|
* Detects that a target element's visibility.
|
|
*
|
|
* @see https://vueuse.org/useIntersectionObserver
|
|
* @param target
|
|
* @param callback
|
|
* @param options
|
|
*/
|
|
export declare function useIntersectionObserver(
|
|
target:
|
|
| MaybeComputedElementRef
|
|
| MaybeRefOrGetter<MaybeElement[]>
|
|
| MaybeComputedElementRef[],
|
|
callback: IntersectionObserverCallback,
|
|
options?: UseIntersectionObserverOptions,
|
|
): UseIntersectionObserverReturn
|
|
```
|