{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"scroll-snap-full-height-sections-with-gentle-parallax","type":"registry:block","title":"Scroll Snap Full Height Sections With Gentle Parallax","description":"","dependencies":[],"files":[{"path":"components/we-inc/scroll-snap-full-height-sections-with-gentle-parallax.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\nconst SHIFT = 8; // how far each photo drifts inside its section, as a percentage of the photo height\nconst STOPS = [\n  { id: \"w6snp-01\", src: \"https://images.pexels.com/photos/35972428/pexels-photo-35972428.jpeg?auto=compress&cs=tinysrgb&w=1600\", alt: \"Golden sand dunes rolling under a clear blue sky\", num: \"01\", title: \"Arrive at the edge\", text: \"The road ends at the last well. From there it is camels, or your own feet, for the final hour in.\" },\n  { id: \"w6snp-02\", src: \"https://images.pexels.com/photos/2563810/pexels-photo-2563810.jpeg?auto=compress&cs=tinysrgb&w=1600\", alt: \"Close view of wind ripples across a soft grey-gold dune\", num: \"02\", title: \"Walk the ridges\", text: \"Mornings start before the heat, along the dune crests, with a guide who reads the sand like a map.\" },\n  { id: \"w6snp-03\", src: \"https://images.pexels.com/photos/2504713/pexels-photo-2504713.jpeg?auto=compress&cs=tinysrgb&w=1600\", alt: \"Long dunes with ripple patterns running down to a calm sea at dusk\", num: \"03\", title: \"Sleep by the water\", text: \"The last camp sits where the dunes meet the sea. Dinner is cooked on coals and served on the sand.\" },\n];\n\nexport default function ScrollSnapFullHeightSectionsWithGentleParallax() {\n  const box = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    const el = box.current;\n    if (!el) return;\n    const imgs = Array.from(el.querySelectorAll<HTMLImageElement>(\".w6snp-img\"));\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    let frame = 0;\n    let on = true;\n    const draw = () => {\n      frame = 0;\n      el.classList.toggle(\"w6snp-moved\", el.scrollTop > 8);\n      if (reduce) return;\n      const h = el.clientHeight || 1;\n      imgs.forEach((img, i) => {\n        const p = Math.max(-1, Math.min(1, (i * h - el.scrollTop) / h)); // 0 when this section fills the box\n        img.style.transform = `translate3d(0,${(p * SHIFT).toFixed(2)}%,0)`;\n      });\n    };\n    const req = () => {\n      if (on && !frame) frame = requestAnimationFrame(draw);\n    };\n    const io = new IntersectionObserver(([e]) => {\n      on = e.isIntersecting;\n      if (on) req();\n    });\n    io.observe(el);\n    el.addEventListener(\"scroll\", req, { passive: true });\n    req();\n    return () => {\n      cancelAnimationFrame(frame);\n      io.disconnect();\n      el.removeEventListener(\"scroll\", req);\n    };\n  }, []);\n\n  return (\n    <div ref={box} tabIndex={0} role=\"region\" aria-label=\"Erg Saffa desert journey, scrollable preview\" className=\"w6snp relative h-[600px] snap-y snap-mandatory overflow-y-auto overscroll-contain bg-[#2a1d14] text-white outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[#f3e3c7]\">\n      <style>{`\n        .w6snp-img { will-change: transform; }\n        .w6snp-hint { transition: opacity .5s ease; }\n        .w6snp-moved .w6snp-hint { opacity: 0; }\n        @media (prefers-reduced-motion: reduce) { .w6snp-img { will-change: auto; } }\n      `}</style>\n      {STOPS.map((s, i) => (\n        <section key={s.id} id={s.id} className=\"relative h-[600px] snap-start overflow-hidden\">\n          <img src={s.src} alt={s.alt} width={1600} height={1067} className=\"w6snp-img absolute inset-x-0 top-[-10%] h-[120%] w-full object-cover\" />\n          <div aria-hidden=\"true\" className=\"absolute inset-0 bg-gradient-to-t from-[#1d130c]/85 via-[#1d130c]/15 to-[#1d130c]/40\" />\n          {i === 0 && (\n            <>\n              <p className=\"absolute left-6 top-8 text-xs font-semibold uppercase tracking-[0.28em] text-[#f3e3c7] sm:left-12\">Erg Saffa Camps</p>\n              <span className=\"w6snp-hint pointer-events-none absolute right-4 top-6 rounded-full bg-[#f3e3c7] px-3 py-1.5 text-xs font-medium text-[#2a1d14]\" aria-hidden=\"true\">Scroll inside</span>\n            </>\n          )}\n          <div className=\"absolute inset-x-0 bottom-0 px-6 pb-12 sm:px-12\">\n            <p className=\"text-sm font-semibold tabular-nums text-[#f3e3c7]\">{s.num} / 03</p>\n            <h2 className=\"mt-2 text-4xl font-semibold leading-tight sm:text-5xl\">{s.title}</h2>\n            <p className=\"mt-3 max-w-md text-base leading-relaxed text-[#efe6d8]\">{s.text}</p>\n            {i === STOPS.length - 1 && (\n              <a href=\"#\" className=\"mt-6 inline-flex h-12 items-center rounded-full bg-[#f3e3c7] px-6 text-sm font-semibold text-[#2a1d14] hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-offset-2 focus-visible:ring-offset-[#2a1d14]\">See spring departures</a>\n            )}\n          </div>\n        </section>\n      ))}\n    </div>\n  );\n}\n"}]}
