Getting Started
Components
Special Effects
Animations
Text Animations
Backgrounds
A description for Retro Grid component.
Retro Grid
retro-grid.svelte
<script> import { RetroGrid } from "$lib/components/magic/retro-grid/index.js";</script>
<div class="bg-background relative flex h-125 w-full flex-col items-center justify-center overflow-hidden rounded-lg border"> <span class="pointer-events-none z-10 bg-linear-to-b from-[#ffd319] via-[#ff2975] to-[#8c1eff] bg-clip-text text-center text-7xl leading-none font-bold tracking-tighter whitespace-pre-wrap text-transparent" > Retro Grid </span> <RetroGrid /></div>Installation
pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/r/retro-grid.json
Copy the Source Code
Copy and paste the following code into your project:
retro-grid.svelte
<script lang="ts"> import { cn } from "#lib/utils.js"; import type { ClassValue, HTMLAttributes } from "svelte/elements";
interface RetroGridProps extends HTMLAttributes<HTMLDivElement> { class?: ClassValue; angle?: number; cellSize?: number; opacity?: number; lightLineColor?: string; darkLineColor?: string; }
let { class: className, angle = 65, cellSize = 60, opacity = 0.5, lightLineColor = "gray", darkLineColor = "gray", ...props }: RetroGridProps = $props();</script>
<div class={cn( "pointer-events-none absolute size-full overflow-hidden perspective-[200px]", `opacity-(--opacity)`, className )} style=" --grid-angle: {angle}deg; --cell-size: {cellSize}px; --opacity: {opacity}; --light-line: {lightLineColor}; --dark-line: {darkLineColor};" {...props}> <div class="absolute inset-0 transform-[rotateX(var(--grid-angle))]"> <div class="animate-grid inset-[0%_0px] ml-[-200%] h-[300vh] w-[600vw] origin-[100%_0_0] bg-[linear-gradient(to_right,var(--light-line)_1px,transparent_0),linear-gradient(to_bottom,var(--light-line)_1px,transparent_0)] bg-size-[var(--cell-size)_var(--cell-size)] bg-repeat dark:bg-[linear-gradient(to_right,var(--dark-line)_1px,transparent_0),linear-gradient(to_bottom,var(--dark-line)_1px,transparent_0)]" ></div> </div>
<div class="absolute inset-0 bg-linear-to-t from-white to-transparent to-90% dark:from-black" ></div></div> index.ts
export { default as RetroGrid } from "./retro-grid.svelte";Add Tailwind CSS
Add the following to your routes/layout.css file:
src/routes/layout.css
@theme inline { --animate-grid: grid 15s linear infinite;
@keyframes grid { 0% { transform: translateY(-50%); } 100% { transform: translateY(0); } }}Folder Structure
Folder Structure
src/└── lib/ └── components/ └── magic/ └── retro-grid/ ├── retro-grid.svelte └── index.tsInstall and integrate the Svelte component documented below.https://sv-animations.vercel.app/magic/docs/components/retro-grid/llms.txt
Follow the guide's installation and usage instructions.Match the project's existing structure, imports, and styles.Keep changes scoped to the component and verify it works.Reply with a short bullet list of completed changes.Usage
<script lang="ts"> import { RetroGrid } from "#lib/components/magic/retro-grid/index.js";</script>
<div class="relative h-64 overflow-hidden"> <RetroGrid /></div>Props
Retro Grid
A component for Retro Grid.
| Name | Type | Default | Description |
|---|---|---|---|
class | ClassValue | "" | Additional CSS classes to apply |
angle | number | 65 | Rotation angle of the grid in degrees |
cellSize | number | 60 | Size of each grid cell in pixels |
opacity | number | 0.5 | Opacity of the grid lines (0 to 1) |
lightLineColor | string | "gray" | Color of the light grid lines |
darkLineColor | string | "gray" | Color of the dark grid lines |