Neon Gradient Card
svelte-animations/neon-gradient-cardFreeBlock
A card component with animated neon gradient borders and customizable colors, border size, and radius.
Install it
npx shadcn@latest add https://sv-animations.vercel.app/r/neon-gradient-card.jsonSource
1<script lang="ts">2 import { onMount } from "svelte";3 import { cn } from "$UTILS$";4 import type { Snippet } from "svelte";56 interface NeonColorsProps {7 firstColor: string;8 secondColor: string;9 }1011 interface NeonGradientCardProps {12 children?: Snippet;13 class?: string;14 borderSize?: number;15 borderRadius?: number;16 neonColors?: NeonColorsProps;17 }1819 let {20 class: className,21 children,22 borderSize = 2,23 borderRadius = 20,24 neonColors = {25 firstColor: "#ff00aa",26 secondColor: "#00FFF1",27 },28 ...props29 }: NeonGradientCardProps = $props();3031 let containerRef: HTMLDivElement | null = $state(null);32 let dimensions = $state({ width: 0, height: 0 });3334 const updateDimensions = () => {35 if (containerRef) {36 const { offsetWidth, offsetHeight } = containerRef;37 dimensions = { width: offsetWidth, height: offsetHeight };38 }39 };4041 onMount(() => {42 updateDimensions();43 window.addEventListener("resize", updateDimensions);4445 return () => {46 window.removeEventListener("resize", updateDimensions);47 };48 });4950 $effect(() => {51 if (containerRef) {52 updateDimensions();53 }54 });5556 let containerStyle = $derived(`57 --border-size: ${borderSize}px;58 --border-radius: ${borderRadius}px;59 --neon-first-color: ${neonColors.firstColor};60 --neon-second-color: ${neonColors.secondColor};61 --card-width: ${dimensions.width}px;62 --card-height: ${dimensions.height}px;63 --card-content-radius: ${borderRadius - borderSize}px;64 --pseudo-element-background-image: linear-gradient(0deg, ${neonColors.firstColor}, ${neonColors.secondColor});65 --pseudo-element-width: ${dimensions.width + borderSize * 2}px;66 --pseudo-element-height: ${dimensions.height + borderSize * 2}px;67 --after-blur: ${dimensions.width / 3}px;68 `);69</script>7071<div72 bind:this={containerRef}73 style={containerStyle}74 class={cn("relative z-10 size-full rounded-(--border-radius)", className)}75 {...props}76>77 <div78 class={cn(79 "relative size-full min-h-[inherit] rounded-(--card-content-radius) bg-gray-100 p-6",80 "before:absolute before:-top-(--border-size) before:-left-(--border-size) before:-z-10 before:block",81 "before:h-(--pseudo-element-height) before:w-(--pseudo-element-width) before:rounded-(--border-radius) before:content-['']",82 "before:bg-[linear-gradient(0deg,var(--neon-first-color),var(--neon-second-color))] before:bg-size-[100%_200%]",83 "before:animate-background-position-spin",84// … 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 |
