mirror of
https://github.com/hanzoai/site.git
synced 2026-11-20 21:21:13 +00:00
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01DqUybA3gCfaruBE8tifYd5
17 lines
943 B
JavaScript
17 lines
943 B
JavaScript
// Scroll helpers that work the same with or without Lenis (components/Chrome.jsx runs Lenis unless reduced motion).
|
|
// HOW TO USE: import { scrollToEl, scrollToY } from '../lib/scroll'; scrollToEl(el, { offset: -110 })
|
|
// The offset clears Hanzo's 60 px sticky header; reduced motion jumps instead of gliding.
|
|
const calm = () => typeof matchMedia !== 'undefined' && matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
|
|
export function scrollToY(y, { duration = 1.1, immediate = false } = {}) {
|
|
const l = typeof window !== 'undefined' && window.__lenis;
|
|
if (l) l.scrollTo(y, { duration, immediate: immediate || calm(), force: true });
|
|
else window.scrollTo({ top: y, behavior: immediate || calm() ? 'auto' : 'smooth' });
|
|
}
|
|
|
|
export function scrollToEl(el, { offset = -80, duration, immediate } = {}) {
|
|
if (!el) return;
|
|
const y = el.getBoundingClientRect().top + window.scrollY + offset;
|
|
scrollToY(y, { duration, immediate });
|
|
}
|