Cool Mode
magicui/cool-modeFreeComponent
Cool mode effect for buttons, links, and other DOMs
Live preview
live · rendered by the registry
Rendered by magicui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://magicui.design/r/cool-mode.jsonSource
1"use client"23import React, { useEffect, useRef, type ReactNode } from "react"45export interface BaseParticle {6 element: HTMLElement | SVGSVGElement7 left: number8 size: number9 top: number10}1112export interface BaseParticleOptions {13 particle?: string14 size?: number15}1617export interface CoolParticle extends BaseParticle {18 direction: number19 speedHorz: number20 speedUp: number21 spinSpeed: number22 spinVal: number23}2425export interface CoolParticleOptions extends BaseParticleOptions {26 particleCount?: number27 speedHorz?: number28 speedUp?: number29}3031const SVG_NS = "http://www.w3.org/2000/svg"3233const getContainer = () => {34 const id = "_coolMode_effect"35 const existingContainer = document.getElementById(id)3637 if (existingContainer) {38 return existingContainer39 }4041 const container = document.createElement("div")42 container.setAttribute("id", id)43 container.setAttribute(44 "style",45 "overflow:hidden; position:fixed; height:100%; top:0; left:0; right:0; bottom:0; pointer-events:none; z-index:2147483647"46 )4748 document.body.appendChild(container)4950 return container51}5253let instanceCounter = 05455const applyParticleEffect = (56 element: HTMLElement,57 options?: CoolParticleOptions58): (() => void) => {59 instanceCounter++6061 const defaultParticle = "circle"62 const particleType = options?.particle || defaultParticle63 const sizes = [15, 20, 25, 35, 45]64 const limit = 456566 let particles: CoolParticle[] = []67 let autoAddParticle = false68 let mouseX = 069 let mouseY = 07071 const container = getContainer()7273 const appendCircleParticle = (particle: HTMLDivElement, size: number) => {74 const circleSVG = document.createElementNS(SVG_NS, "svg")75 const circle = document.createElementNS(SVG_NS, "circle")7677 circle.setAttributeNS(null, "cx", (size / 2).toString())78 circle.setAttributeNS(null, "cy", (size / 2).toString())79 circle.setAttributeNS(null, "r", (size / 2).toString())80 circle.setAttributeNS(null, "fill", `hsl(${Math.random() * 360}, 70%, 50%)`)8182 circleSVG.appendChild(circle)83 circleSVG.setAttribute("width", size.toString())84 circleSVG.setAttribute("height", size.toString())8586 particle.appendChild(circleSVG)87 }8889 const appendImageParticle = (90 particle: HTMLDivElement,91 imageSrc: string,92 size: number93 ) => {94 const image = document.createElement("img")95 image.src = imageSrc96 image.width = size97 image.height = size98 image.alt = ""99 image.style.borderRadius = "50%"100101// … truncated
Files it writes
More from magicui
All 247 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Androidandroid | magicui | Components | Free | no deps | |
| Animated Beamanimated-beam | magicui | Components | Free | 1 dep | |
| Animated Circular Progress Baranimated-circular-progress-bar | magicui | Components | Free | no deps | |
| Animated Gradient Textanimated-gradient-text | magicui | Components | Free | no deps | |
| Animated Grid Patternanimated-grid-pattern | magicui | Components | Free | 1 dep | |
| Animated Listanimated-list | magicui | Components | Free | 1 dep | |
| Animated Shiny Textanimated-shiny-text | magicui | Components | Free | no deps | |
| Theme Toggleranimated-theme-toggler | magicui | Components | Free | 1 dep |
