horizontal-scroll
obsidianui/horizontal-scrollFreeComponent
obsidianui publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by obsidianui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://obsidianui.dev/r/horizontal-scroll.jsonSource
1'use client';23import React, { useRef } from 'react';4import Image from 'next/image';5import { motion, MotionValue, useScroll, useTransform } from 'framer-motion';67const HorizontalScrollItem = ({8 image,9 index,10 isLeft,11 scrollYProgress,12 totalItems13}: {14 image: string;15 index: number;16 isLeft: boolean;17 scrollYProgress: MotionValue<number>;18 totalItems: number;19}) => {20 const direction = isLeft ? -1 : 1;21 const position = index / totalItems;2223 const translateX = useTransform(24 scrollYProgress,25 [0, position, 1],26 [-index * 500 * direction, 0, (totalItems - index) * 500 * direction]27 );28 const rotateY = useTransform(29 scrollYProgress,30 [0, position, 1],31 [index * 35 * direction, 0, (totalItems - index) * -35 * direction]32 );33 const blur = useTransform(scrollYProgress, [0, position, 1], [index * 2, 0, (totalItems - index) * 2]);34 const contrast = useTransform(scrollYProgress, [0, position, 1], [index * 0.5, 1, (totalItems - index) * 0.5]);3536 const translateY = useTransform(37 scrollYProgress,38 [0, position, 1],39 [(totalItems - index) * 20, totalItems * 20, index * 20]40 );4142 const filter = useTransform([blur, contrast], ([blur, contrast]) => `blur(${blur}px) contrast(${contrast})`);4344 return (45 <motion.div46 style={{47 translateX,48 filter,49 translateY: useTransform(translateY, (value) => `${value - 400}px`),50 perspective: 1000,51 transformStyle: 'preserve-3d'52 }}53 className="h-[300px] max-w-sm w-full absolute rounded-xl overflow-visible"54 >55 <motion.div style={{ rotateY }}>56 <Image src={image} alt={image} width={1000} height={1000} className="object-cover h-[300px] w-full rounded-xl" />57 </motion.div>58 </motion.div>59 );60};6162interface HorizontalScrollProps {63 items: { image: string }[];64}6566export function HorizontalScroll({ items }: HorizontalScrollProps) {67 const ref = useRef<HTMLDivElement>(null);6869 const { scrollYProgress } = useScroll({70 container: ref,71 offset: ['start start', 'end end']72 });7374 return (75 <div ref={ref} className="h-full w-full overflow-y-auto relative" style={{ minHeight: '400px' }}>76 <div className="h-full w-full absolute top-0 left-0">77// … truncated
What it pulls in
npm packages
Files it writes
More from obsidianui
All 111 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-inputai-input | obsidianui | Components | Free | 2 deps | |
| alertalert | obsidianui | Components | Free | no deps | |
| animated-tab-baranimated-tab-bar | obsidianui | Components | Free | no deps | |
| apple-spotlightapple-spotlight | obsidianui | Components | Free | 2 deps | |
| avataravatar | obsidianui | Components | Free | 1 dep | |
| badgebadge | obsidianui | Components | Free | 1 dep | |
| breadcrumbbreadcrumb | obsidianui | Components | Free | 2 deps | |
| buttonbutton | obsidianui | Components | Free | 1 dep |
