Css Box Scroll Demo
fancy/css-box-scroll-demoFreeBlock
A block component.
Install it
npx shadcn@latest add https://www.fancycomponents.dev/r/css-box-scroll-demo.jsonSource
1import { useRef } from "react"2import { useScroll, useTransform } from "motion/react"34import { cn } from "@/lib/utils"5import useScreenSize from "@/hooks/use-screen-size"6import CSSBox, { CSSBoxRef } from "@/components/fancy/blocks/css-box"78const BoxFace = ({9 imageUrl,10 className,11}: {12 imageUrl: string13 className?: string14}) => (15 <div className={cn("w-full h-full relative", className)}>16 <img src={imageUrl} alt="" className="w-full h-full object-cover" />17 <div18 className="absolute inset-0"19 style={{20 maskImage: "linear-gradient(to top, white 20%, transparent 100%)",21 WebkitMaskImage: "linear-gradient(to top, white 20%, transparent 100%)",22 backgroundColor: "rgba(255,255,255,0.4)",23 backdropFilter: "blur(8px)",24 }}25 >26 <div className="absolute bottom-0 w-full flex flex-col items-start justify-end pb-3">27 <div className="flex w-full justify-between px-2 items-end">28 <div className="text-[8px] font-black pb-1">JUN14</div>29 <div className="text-3xl md:text-5xl font-black px-2">30 New Arrivals31 </div>32 <div className="text-lg md:text-xl font-medium">SS25</div>33 </div>34 </div>35 </div>36 </div>37)3839export default function CSSBoxScrollDemo() {40 const boxRef = useRef<CSSBoxRef>(null)41 const containerRef = useRef<HTMLDivElement>(null)42 const screenSize = useScreenSize()4344 const { scrollYProgress } = useScroll({45 container: containerRef,46 })4748 // Transform scroll progress (0-1) to rotation (0-360)49 const rotation = useTransform(scrollYProgress, [0, 1], [0, 360])5051 // Update box rotation when scroll transform changes52 rotation.on("change", (latest) => {53 boxRef.current?.rotateTo(0, latest)54 })5556 const imageUrl =57 "https://cdn.cosmos.so/276cdd4e-8a7a-4c32-955f-83c5900a0926?format=jpeg"5859 const boxWidth = screenSize.lessThan("md") ? 220 : 30060 const boxHeight = screenSize.lessThan("md") ? 300 : 40061 const boxDepth = screenSize.lessThan("md") ? 220 : 3006263 return (64 <div65 ref={containerRef}66 className="relative w-dvw h-dvh overflow-y-auto bg-[#fefefe] flex"67 >68 <div className="h-[400%] flex w-full items-start justify-center absolute">69 <div className="sticky py-28 md:py-16 top-0 left-0 px-6 md:px-12">70 <CSSBox71 ref={boxRef}72 width={boxWidth}73 height={boxHeight}74 depth={boxDepth}75 perspective={2000}76// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from fancy
All 158 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Gradient Demoanimated-gradient-demo | fancy | Blocks | Free | no deps | |
| Basic Number Ticker Demobasic-number-ticker-demo | fancy | Blocks | Free | no deps | |
| Box Carousel Autoplay Demobox-carousel-autoplay-demo | fancy | Blocks | Free | 1 dep | |
| Box Carousel Demobox-carousel-demo | fancy | Blocks | Free | 1 dep | |
| Box Carousel Video Demobox-carousel-video-demo | fancy | Blocks | Free | 1 dep | |
| Breathing Text Demobreathing-text-demo | fancy | Blocks | Free | no deps | |
| Circling Elements Democircling-elements-demo | fancy | Blocks | Free | no deps | |
| Circling Elements Easing Democircling-elements-easing-demo | fancy | Blocks | Free | no deps |
