Bubble Background
nyxui/bubble-backgroundFreeComponent
An interactive fluid bubble background component with animated colorful blobs that respond to user interaction.
Live preview
live · rendered by the registry
Rendered by shadcn/ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://nyxui.com/r/bubble-background.jsonSource
1"use client";23import React, { useEffect, useRef } from "react";4import type { CSSProperties } from "react";56interface BubblesProps {7 bgColorA?: string;8 bgColorB?: string;9 bubbleColors?: {10 colorA?: string;11 colorB?: string;12 colorC?: string;13 colorD?: string;14 colorE?: string;15 interactive?: string;16 };17 blendMode?: CSSProperties["mixBlendMode"];18 bubbleSize?: string;19}2021const defaultBubbleColors = {22 colorA: "18, 113, 255",23 colorB: "221, 74, 255",24 colorC: "100, 220, 255",25 colorD: "200, 50, 50",26 colorE: "180, 180, 50",27 interactive: "148, 100, 255",28};2930export function BubbleBackground({31 bgColorA = "rgb(108, 0, 162)",32 bgColorB = "rgb(0, 17, 82)",33 bubbleColors = defaultBubbleColors,34 blendMode = "hard-light",35 bubbleSize = "80%",36}: BubblesProps) {37 const interactiveRef = useRef<HTMLDivElement>(null);3839 useEffect(() => {40 let curX = 0;41 let curY = 0;42 let tgX = 0;43 let tgY = 0;44 const easeFactor = 10;45 let animationFrameId: number;4647 function move() {48 if (!interactiveRef.current) return;4950 curX += (tgX - curX) / easeFactor;51 curY += (tgY - curY) / easeFactor;5253 interactiveRef.current.style.transform = `translate(${curX}px, ${curY}px)`;54 animationFrameId = requestAnimationFrame(move);55 }5657 const handlePointerMove = (e: PointerEvent) => {58 tgX = e.clientX;59 tgY = e.clientY;60 };6162 window.addEventListener("pointermove", handlePointerMove);63 animationFrameId = requestAnimationFrame(move);6465 return () => {66 window.removeEventListener("pointermove", handlePointerMove);67 cancelAnimationFrame(animationFrameId);68 };69 }, []);7071 // Calculate common positions72 const centerTop = `calc(50% - ${bubbleSize} / 2)`;73 const centerLeft = `calc(50% - ${bubbleSize} / 2)`;7475 return (76 <div77 className="w-screen h-screen relative overflow-hidden"78 style={{79 background: `linear-gradient(40deg, ${bgColorA}, ${bgColorB})`,80 }}81 >82 <svg className="absolute w-0 h-0">83 <filter id="goo">84 <feGaussianBlur in="SourceGraphic" stdDeviation="10" result="blur" />85 <feGaussianBlur in="SourceGraphic" stdDeviation="10" result="blur" />86 <feColorMatrix87 in="blur"88 mode="matrix"89 values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 18 -8"90 result="goo"91 />92 <feBlend in="SourceGraphic" in2="goo" />93 </filter>94 </svg>9596 <div97// … truncated
Files it writes
More from shadcn/ui
All 68 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| 3D Layered Card3d-layered-card | shadcn/ui | Components | Free | 1 dep | |
| Animated Code Blockanimated-code-block | shadcn/ui | Components | Free | 3 deps | |
| Animated Grainy Backgroundanimated-grainy-bg | shadcn/ui | Components | Free | 1 dep | |
| Animated Textanimated-text | shadcn/ui | Components | Free | 1 dep | |
| Apple Glass Effectapple-glass-effect | shadcn/ui | Components | Free | 1 dep | |
| Custom Cursorcustom-cursor | shadcn/ui | Components | Free | 1 dep | |
| Cyberpunk Cardcyberpunk-card | shadcn/ui | Components | Free | no deps | |
| Dynamic Rippledynamic-ripple | shadcn/ui | Components | Free | no deps |
