Container Scroll
godui/container-scrollFreeComponent
A device frame that un-tilts from a 3D perspective and scales to rest as you scroll — the classic product hero.
Install it
npx shadcn@latest add https://godui.design/r/container-scroll.jsonSource
1"use client";23import {4 motion,5 useReducedMotion,6 useScroll,7 useSpring,8 useTransform,9} from "framer-motion";10import * as React from "react";1112export type ContainerScrollProps = React.HTMLAttributes<HTMLDivElement> & {13 /** Headline block rendered above the device, rising as you scroll. */14 header?: React.ReactNode;15 /** The "screen" content — an image, video, or live UI. */16 children: React.ReactNode;17};1819// SPRING.smooth — surfaces / shared-layout feel.20const SPRING = { stiffness: 320, damping: 32, mass: 0.9 } as const;2122const ContainerScroll = React.forwardRef<HTMLDivElement, ContainerScrollProps>(23 ({ header, children, className, ...props }, ref) => {24 const reduce = useReducedMotion();25 const containerRef = React.useRef<HTMLDivElement>(null);26 React.useImperativeHandle(27 ref,28 () => containerRef.current as HTMLDivElement,29 );3031 const { scrollYProgress } = useScroll({ target: containerRef });3233 const rotateX = useSpring(34 useTransform(scrollYProgress, [0, 1], [20, 0]),35 SPRING,36 );37 const scale = useSpring(38 useTransform(scrollYProgress, [0, 1], [1.05, 1]),39 SPRING,40 );41 const translateY = useSpring(42 useTransform(scrollYProgress, [0, 1], [0, -100]),43 SPRING,44 );4546 const frame = (47 <div className="mx-auto w-full max-w-5xl rounded-2xl border border-border bg-card p-2 shadow-2xl md:p-3">48 <div className="aspect-[16/10] size-full overflow-hidden rounded-xl bg-muted [&>img]:size-full [&>img]:object-cover [&>video]:size-full [&>video]:object-cover">49 {children}50 </div>51 </div>52 );5354 // Reduced motion: a calm, upright device with no scroll-driven transforms.55 if (reduce) {56 return (57 <div58 ref={containerRef}59 data-slot="container-scroll"60 className={`flex flex-col items-center px-4 py-16 ${className ?? ""}`}61 {...props}62 >63 {header ? <div className="mb-10 text-center">{header}</div> : null}64 {frame}65 </div>66 );67 }6869 return (70 <div71 ref={containerRef}72 data-slot="container-scroll"73 className={`relative flex h-[60rem] items-center justify-center p-4 md:h-[80rem] md:p-20 ${className ?? ""}`}74 {...props}75 >76 <div className="relative w-full [perspective:1000px]">77 {header ? (78 <motion.div79 style={{ translateY }}80// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from godui
All 105 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | godui | Components | Free | 1 dep | |
| Agent Flowagent-flow | godui | Components | Free | 1 dep | |
| Agent Timelineagent-timeline | godui | Components | Free | 1 dep | |
| Animated Beamanimated-beam | godui | Components | Free | 1 dep | |
| Animated Testimonialsanimated-testimonials | godui | Components | Free | 1 dep | |
| Animated Tooltipanimated-tooltip | godui | Components | Free | 1 dep | |
| App Showcaseapp-showcase | godui | Components | Free | 1 dep | |
| Aurora Textaurora-text | godui | Components | Free | no deps |
