Image Trail
fancy/image-trailFreeComponent
A ui component.
Install it
npx shadcn@latest add https://www.fancycomponents.dev/r/image-trail.jsonSource
1// author: Khoa Phan <https://www.pldkhoa.dev>23"use client"45import React, { ElementType, HTMLAttributes, useEffect, useMemo } from "react"6import type { DOMKeyframesDefinition, AnimationOptions } from "motion"7import { useAnimate } from "motion/react"89import { cn } from "@/lib/utils"1011interface ImageTrailProps extends HTMLAttributes<HTMLDivElement> {12 /**13 * The content to be displayed14 */15 children: React.ReactNode1617 /**18 * HTML Tag19 */20 as?: ElementType2122 /**23 * How much distance in pixels the mouse has to travel to trigger of an element to appear.24 */25 threshold?: number2627 /**28 * The intensity for the momentum movement after showing the element. The value will be clamped > 0 and <= 1.0. Defaults to 0.3.29 */30 intensity?: number3132 /**33 * Animation Keyframes for defining the animation sequence. Example: { scale: [0, 1, 1, 0] }34 */35 keyframes?: DOMKeyframesDefinition3637 /**38 * Options for the animation/keyframes. Example: { duration: 1, times: [0, 0.1, 0.9, 1] }39 */40 keyframesOptions?: AnimationOptions4142 /**43 * Animation keyframes for the x and y positions after showing the element. Describes how the element should try to arrive at the mouse position.44 */45 trailElementAnimationKeyframes?: {46 x?: AnimationOptions47 y?: AnimationOptions48 }4950 /**51 * The number of times the children will be repeated. Defaults to 3.52 */53 repeatChildren?: number5455 /**56 * The base zIndex for all elements. Defaults to 0.57 */58 baseZIndex?: number5960 /**61 * Controls stacking order behavior.62 * - "new-on-top": newer elements stack above older ones (default)63 * - "old-on-top": older elements stay visually on top64 */65 zIndexDirection?: "new-on-top" | "old-on-top"66}6768interface ImageTrailItemProps extends HTMLAttributes<HTMLDivElement> {69 /**70 * HTML Tag71 */72 as?: ElementType7374 /**75 * The content to be displayed76 */77 children: React.ReactNode78}7980/**81 * Helper functions82 */83const MathUtils = {84 // linear interpolation85 lerp: (a: number, b: number, n: number) => (1 - n) * a + n * b,86 // distance between two points87 distance: (x1: number, y1: number, x2: number, y2: number) =>88 Math.hypot(x2 - x1, y2 - y1),89}9091const ImageTrail = ({92 className,93 as = "div",94 children,95 threshold = 100,96 intensity = 0.3,97 keyframes,98 keyframesOptions,99 repeatChildren = 3,100 trailElementAnimationKeyframes = {101 x: { duration: 1, type: "tween", ease: "easeOut" },102// … truncated
What it pulls in
npm packages
Files it writes
More from fancy
All 158 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Gradient With Svganimated-gradient-with-svg | fancy | Components | Free | no deps | |
| Basic Number Tickerbasic-number-ticker | fancy | Components | Free | 1 dep | |
| Box Carouselbox-carousel | fancy | Components | Free | 1 dep | |
| Breathing Textbreathing-text | fancy | Components | Free | 1 dep | |
| Circling Elementscircling-elements | fancy | Components | Free | 1 dep | |
| Css Boxcss-box | fancy | Components | Free | 1 dep | |
| Cursor Attractor And Gravitycursor-attractor-and-gravity | fancy | Components | Free | 5 deps | |
| Drag Elementsdrag-elements | fancy | Components | Free | 1 dep |
