hover-img
obsidianui/hover-imgFreeComponent
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/hover-img.jsonSource
1"use client";23import React, { useRef, useEffect } from "react";4import gsap from "gsap";5import "./hover-img.css";67interface ProjectItem {8 title: string;9 label: string;10 imageSrc: string;11}1213const defaultProjects: ProjectItem[] = [14 {15 title: "Shree Krishna",16 label: "The Supreme Personality of Godhead",17 imageSrc: "/hover-img/image-1.jpg",18 },19 {20 title: "Radha Krishna",21 label: "The Divine Couple",22 imageSrc: "/hover-img/image-2.jpg",23 },24 {25 title: "Divine Love",26 label: "Eternal Bond",27 imageSrc: "/hover-img/image-3.jpg",28 },29];3031interface HoverImgProps {32 projects?: ProjectItem[];33 className?: string;34 isContained?: boolean; // New prop for grid previews35 compact?: boolean; // New prop for compact layout36}3738export function HoverImg({ projects = defaultProjects, className, isContained = false, compact = false }: HoverImgProps) {39 const containerRef = useRef<HTMLDivElement>(null);40 const thumbnailRef = useRef<HTMLDivElement>(null);41 const xToRef = useRef<gsap.QuickToFunc | null>(null);42 const yToRef = useRef<gsap.QuickToFunc | null>(null);4344 useEffect(() => {45 const projectThumbnail = thumbnailRef.current;46 const projectsContainer = containerRef.current?.querySelector(47 ".hover-img-projects"48 ) as HTMLElement | null;4950 if (!projectThumbnail || !projectsContainer) return;5152 const projectElements = gsap.utils.toArray(53 ".hover-img-project",54 projectsContainer55 ) as HTMLElement[];56 const thumbnails = gsap.utils.toArray(57 ".hover-img-thumbnail",58 projectThumbnail59 ) as HTMLElement[];6061 gsap.set(projectThumbnail, { scale: 0, xPercent: -50, yPercent: -50 });6263 xToRef.current = gsap.quickTo(projectThumbnail, "x", {64 duration: 0.4,65 ease: "power3.out",66 });67 yToRef.current = gsap.quickTo(projectThumbnail, "y", {68 duration: 0.4,69 ease: "power3.out",70 });7172 const handleMouseMove = (e: MouseEvent) => {73 let x = e.clientX;74 let y = e.clientY;7576 if (isContained && containerRef.current) {77 const rect = containerRef.current.getBoundingClientRect();78 x = e.clientX - rect.left;79 y = e.clientY - rect.top;80 }8182 xToRef.current?.(x);83// … truncated
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 |
