Cool Mode
svelte-animations/cool-modeFreeBlock
Add a fun particle effect that follows mouse interactions, with support for emojis, images, and custom shapes.
Install it
npx shadcn@latest add https://sv-animations.vercel.app/r/cool-mode.jsonSource
1<script lang="ts">2 import { onMount, onDestroy } from "svelte";3 import type { Snippet } from "svelte";45 export interface BaseParticle {6 element: HTMLElement | SVGSVGElement;7 left: number;8 size: number;9 top: number;10 }1112 export interface BaseParticleOptions {13 particle?: string;14 size?: number;15 }1617 export interface CoolParticle extends BaseParticle {18 direction: number;19 speedHorz: number;20 speedUp: number;21 spinSpeed: number;22 spinVal: number;23 }2425 export interface CoolParticleOptions extends BaseParticleOptions {26 particleCount?: number;27 speedHorz?: number;28 speedUp?: number;29 }3031 interface CoolModeProps {32 children: Snippet;33 options?: CoolParticleOptions;34 }3536 let { children, options }: CoolModeProps = $props();3738 let ref: HTMLSpanElement;39 let cleanup: (() => void) | undefined;4041 const getContainer = () => {42 const id = "_coolMode_effect";43 const existingContainer = document.getElementById(id);4445 if (existingContainer) {46 return existingContainer;47 }4849 const container = document.createElement("div");50 container.setAttribute("id", id);51 container.setAttribute(52 "style",53 "overflow:hidden; position:fixed; height:100%; top:0; left:0; right:0; bottom:0; pointer-events:none; z-index:2147483647"54 );5556 document.body.appendChild(container);5758 return container;59 };6061 let instanceCounter = 0;6263 const applyParticleEffect = (64 element: HTMLElement,65 options?: CoolParticleOptions66 ): (() => void) => {67 instanceCounter++;6869 const defaultParticle = "circle";70 const particleType = options?.particle || defaultParticle;71 const sizes = [15, 20, 25, 35, 45];72 const limit = 45;7374 let particles: CoolParticle[] = [];75 let autoAddParticle = false;76 let mouseX = 0;77 let mouseY = 0;7879 const container = getContainer();8081 function generateParticle() {82 const size = options?.size || sizes[Math.floor(Math.random() * sizes.length)];83 const speedHorz = options?.speedHorz || Math.random() * 10;84 const speedUp = options?.speedUp || Math.random() * 25;85 const spinVal = Math.random() * 360;86 const spinSpeed = Math.random() * 35 * (Math.random() <= 0.5 ? -1 : 1);87 const top = mouseY - size / 2;88 const left = mouseX - size / 2;89 const direction = Math.random() <= 0.5 ? -1 : 1;9091 const particle = document.createElement("div");9293 if (particleType === "circle") {94 const svgNS = "http://www.w3.org/2000/svg";95 const circleSVG = document.createElementNS(svgNS, "svg");96// … truncated
Files it writes
More from Svelte Animations
All 66 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Beamanimated-beam | Svelte Animations | Blocks | Free | 1 dep · 6 files | |
| Animated Circular Progress Baranimated-circular-progress-bar | Svelte Animations | Blocks | Free | no deps · 2 files | |
| Animated Gradient Textanimated-gradient-text | Svelte Animations | Blocks | Free | no deps · 2 files | |
| Animated Grid Patternanimated-grid-pattern | Svelte Animations | Blocks | Free | 1 dep · 2 files | |
| Animated Listanimated-list | Svelte Animations | Blocks | Free | 1 dep · 2 files | |
| Animated Shiny Textanimated-shiny-text | Svelte Animations | Blocks | Free | no deps | |
| Animated Theme Toggleranimated-theme-toggler | Svelte Animations | Blocks | Free | no deps · 2 files | |
| Arc Timelinearc-timeline | Svelte Animations | Blocks | Free | no deps · 3 files |
