{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"floating-product-photo-rising-over-its-backdrop-on-scroll","type":"registry:block","title":"Floating Product Photo Rising Over Its Backdrop on Scroll","description":"","dependencies":[],"files":[{"path":"components/we-inc/floating-product-photo-rising-over-its-backdrop-on-scroll.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\nconst LIFT = 48; // px the product rises across the section\nconst SINK = 28; // px the backdrop sinks the other way\nconst NOTES = [\"Cold-pressed rosehip and sea buckthorn\", \"Thirty millilitres, about two months of evenings\", \"Glass bottle, refill pouch on request\"];\n\nexport default function FloatingProductPhotoRisingOverItsBackdropOnScroll() {\n  const box = useRef<HTMLDivElement>(null);\n  const stage = useRef<HTMLDivElement>(null);\n  const card = useRef<HTMLDivElement>(null);\n  const back = useRef<HTMLDivElement>(null);\n  const shadow = useRef<HTMLDivElement>(null);\n\n  useEffect(() => {\n    const el = box.current;\n    if (!el) return;\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(\"w6prd-moved\", el.scrollTop > 8);\n      if (reduce || !stage.current || !card.current || !back.current || !shadow.current) return;\n      const b = el.getBoundingClientRect(); // page scroll: use { top: 0, height: innerHeight }\n      const r = stage.current.getBoundingClientRect();\n      const p = Math.max(-1, Math.min(1, (r.top + r.height / 2 - (b.top + b.height / 2)) / (b.height / 2 + r.height / 2)));\n      const near = 1 - Math.abs(p);\n      card.current.style.transform = `translate3d(0,${(p * LIFT).toFixed(1)}px,0) scale(${(0.96 + near * 0.04).toFixed(4)})`;\n      back.current.style.transform = `translate3d(0,${(-p * SINK).toFixed(1)}px,0)`;\n      shadow.current.style.opacity = (0.35 + near * 0.65).toFixed(3);\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    window.addEventListener(\"resize\", req);\n    req();\n    return () => {\n      cancelAnimationFrame(frame);\n      io.disconnect();\n      el.removeEventListener(\"scroll\", req);\n      window.removeEventListener(\"resize\", req);\n    };\n  }, []);\n\n  return (\n    <div ref={box} tabIndex={0} role=\"region\" aria-label=\"Saltgrass Apothecary face oil, scrollable preview\" className=\"w6prd relative h-[640px] overflow-y-auto overflow-x-hidden overscroll-contain bg-[#f3e7dc] text-[#3a1f16] outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-[#a5492b]\">\n      <style>{`\n        .w6prd-card, .w6prd-back { will-change: transform; }\n        .w6prd-hint { transition: opacity .5s ease; }\n        .w6prd-moved .w6prd-hint { opacity: 0; }\n        @media (prefers-reduced-motion: reduce) { .w6prd-card, .w6prd-back { will-change: auto; } }\n      `}</style>\n      <span className=\"w6prd-hint pointer-events-none absolute right-4 top-4 z-20 rounded-full bg-[#3a1f16]/85 px-3 py-1.5 text-xs font-medium text-[#f3e7dc]\" aria-hidden=\"true\">Scroll inside</span>\n      <div className=\"mx-auto grid max-w-5xl items-center gap-10 px-6 pb-16 pt-10 md:grid-cols-[1.1fr_1fr] md:pt-12\">\n        <div ref={stage} className=\"relative mx-auto h-[500px] w-full max-w-[420px]\">\n          <div ref={back} aria-hidden=\"true\" className=\"w6prd-back absolute inset-x-4 bottom-0 top-10 rounded-t-full bg-[#b85a3a]\">\n            <span className=\"absolute inset-x-0 top-[22%] text-center text-[80px] font-semibold leading-none tracking-tight text-[#cf7a58]\">No. 4</span>\n          </div>\n          <div ref={shadow} aria-hidden=\"true\" className=\"absolute bottom-6 left-1/2 h-10 w-56 -translate-x-1/2 rounded-[50%] bg-[#3a1f16]/40 blur-xl\" />\n          <div ref={card} className=\"w6prd-card absolute left-1/2 top-[18%] -ml-[115px] w-[230px] overflow-hidden rounded-2xl bg-[#e7e5e2] shadow-[0_30px_60px_-30px_rgba(58,31,22,0.7)] sm:top-[16%]\">\n            <img src=\"https://images.pexels.com/photos/6694147/pexels-photo-6694147.jpeg?auto=compress&cs=tinysrgb&w=800\" alt=\"A brown glass dropper bottle standing on a weathered piece of driftwood against a pale grey wall\" width={800} height={1200} className=\"aspect-[3/4] w-full object-cover\" />\n          </div>\n        </div>\n        <div>\n          <p className=\"text-xs font-semibold uppercase tracking-[0.24em] text-[#a5492b]\">Saltgrass Apothecary</p>\n          <h2 className=\"mt-3 text-4xl font-semibold leading-tight\">Night oil No. 4</h2>\n          <p className=\"mt-4 max-w-sm text-base leading-relaxed text-[#5c3a2d]\">A few drops after washing, pressed in with warm hands. It sinks in before the kettle boils.</p>\n          <ul className=\"mt-6 space-y-3 border-t border-[#3a1f16]/15 pt-6 text-sm text-[#5c3a2d]\">\n            {NOTES.map((n) => (\n              <li key={n} className=\"flex gap-3\"><span aria-hidden=\"true\" className=\"mt-2 h-1.5 w-1.5 shrink-0 rounded-full bg-[#a5492b]\" />{n}</li>\n            ))}\n          </ul>\n          <div className=\"mt-8 flex items-center gap-5\">\n            <a href=\"#\" className=\"inline-flex h-12 items-center rounded-full bg-[#3a1f16] px-6 text-sm font-semibold text-[#f3e7dc] hover:bg-[#5a3326] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3a1f16] focus-visible:ring-offset-2 focus-visible:ring-offset-[#f3e7dc]\">Add to bag, $38</a>\n            <a href=\"#\" className=\"text-sm font-medium underline underline-offset-4 hover:text-[#a5492b] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#a5492b]\">Ingredients</a>\n          </div>\n        </div>\n      </div>\n      <div className=\"h-[360px] border-t border-[#3a1f16]/10 px-6 pt-10 text-center text-sm text-[#6b4a3c]\">Blended in small batches in a coastal workshop and shipped in paper, never plastic.</div>\n    </div>\n  );\n}\n"}]}
