/
githubmirror
/
marktext
Обзор
Документация
Войти
/
githubmirror
/
marktext
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/website/src/hooks/useReveal.ts
40 строк
1021 B
Ran Luo
refactor(website): redesign landing page, drop markdown engine deps (#4312)
29 май 2026, 12:23
Не верифицирован
29 май 2026, 12:23
320255d
Код
Авторство
О чём код?
'use client' import { useEffect } from 'react' export function useReveal() { useEffect(() => { const all = document.querySelectorAll<HTMLElement>('.reveal') if (!('IntersectionObserver' in window)) { all.forEach((el) => el.classList.add('in')) return } const io = new IntersectionObserver( (entries) => { entries.forEach((en) => { if (en.isIntersecting) { ;(en.target as HTMLElement).classList.add('in') io.unobserve(en.target) } }) }, { rootMargin: '0px 0px -8% 0px' } ) all.forEach((el) => io.observe(el)) // Failsafe: embedded/preview environments that never trigger IO callbacks // still need content visible. const failsafe = window.setTimeout(() => { document .querySelectorAll<HTMLElement>('.reveal:not(.in)') .forEach((el) => el.classList.add('in')) }, 1300) return () => { io.disconnect() window.clearTimeout(failsafe) } }, []) }