Float
fancy/floatFreeComponent
A ui component.
Install it
npx shadcn@latest add https://www.fancycomponents.dev/r/float.jsonSource
1"use client"23import React, { useRef } from "react"4import { motion, useAnimationFrame, useMotionValue } from "motion/react"56import { cn } from "@/lib/utils"78type FloatProps = {9 children: React.ReactNode10 speed?: number11 amplitude?: [number, number, number] // [x, y, z]12 rotationRange?: [number, number, number] // [x, y, z]13 timeOffset?: number14 className?: string15}1617const Float: React.FC<FloatProps> = ({18 children,19 speed = 0.5,20 amplitude = [10, 30, 30], // Default [x, y, z] amplitudes21 rotationRange = [15, 15, 7.5], // Default [x, y, z] rotation ranges22 timeOffset = 0,23 className,24}) => {25 const x = useMotionValue(0)26 const y = useMotionValue(0)27 const z = useMotionValue(0)28 const rotateX = useMotionValue(0)29 const rotateY = useMotionValue(0)30 const rotateZ = useMotionValue(0)3132 // Use refs for animation values to avoid recreating the animation frame callback33 const time = useRef(0)3435 useAnimationFrame(() => {36 time.current += speed * 0.023738 // Smooth floating motion on all axes39 const newX = Math.sin(time.current * 0.7 + timeOffset) * amplitude[0]40 const newY = Math.sin(time.current * 0.6 + timeOffset) * amplitude[1]41 const newZ = Math.sin(time.current * 0.5 + timeOffset) * amplitude[2]4243 // 3D rotations with different frequencies for more organic movement44 const newRotateX =45 Math.sin(time.current * 0.5 + timeOffset) * rotationRange[0]46 const newRotateY =47 Math.sin(time.current * 0.4 + timeOffset) * rotationRange[1]48 const newRotateZ =49 Math.sin(time.current * 0.3 + timeOffset) * rotationRange[2]5051 x.set(newX)52 y.set(newY)53 z.set(newZ)54 rotateX.set(newRotateX)55 rotateY.set(newRotateY)56 rotateZ.set(newRotateZ)57 })5859 return (60 <motion.div61 style={{62 x,63 y,64 z,65 rotateX,66 rotateY,67 rotateZ,68 transformStyle: "preserve-3d",69 }}70 className={cn("will-change-transform", className)}71 >72 {children}73 </motion.div>74 )75}7677export default Float
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 |
