Back

Pixel Wave Animation

Retro-style pixel wave loading animation with customizable colors and speed.

Category
LoadingReact
CSS
Custom CSS

Manual

Create a file and paste the following code into it.

src/App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { motion } from "motion/react";

const COLORS = {
  light: "#BAE6FD",
  medium: "#7DD3FC",
  dark: "#38BDF8",
  deep: "#0EA5E9",
};

const SIZES = [
  { label: "Small", grid: 3, pixel: 8, gap: 1 },
  { label: "Medium", grid: 4, pixel: 10, gap: 1 },
  { label: "Large", grid: 5, pixel: 10, gap: 2 },
  { label: "Extra Large", grid: 6, pixel: 12, gap: 2 },
] as const;

function PixelGrid({ grid, pixel, gap }: { grid: number; pixel: number; gap: number }) {
  const pixels = Array.from({ length: grid * grid }, (_, i) => i);

  return (
    <div
      className="grid"
      style={{
        gridTemplateColumns: `repeat(${grid}, ${pixel}px)`,
        gap: `${gap}px`,
      }}
    >
      {pixels.map((i) => {
        const row = Math.floor(i / grid);
        const col = i % grid;
        const colorKeys = Object.values(COLORS);
        const color = colorKeys[(row + col) % colorKeys.length];
        const glowColor = color.replace("#", "");
        const r = parseInt(glowColor.substring(0, 2), 16);
        const g = parseInt(glowColor.substring(2, 4), 16);
        const b = parseInt(glowColor.substring(4, 6), 16);

        return (
          <motion.div
            key={i}
            className="rounded-[2px]"
            style={{
              width: pixel,
              height: pixel,
              backgroundColor: color,
            }}
            animate={{
              opacity: [0.3, 1, 0.3],
              scale: [0.7, 1, 0.7],
              boxShadow: [
                `0 0 0px rgba(${r},${g},${b},0)`,
                `0 0 12px rgba(${r},${g},${b},0.5)`,
                `0 0 0px rgba(${r},${g},${b},0)`,
              ],
            }}
            transition={{
              duration: 1,
              repeat: Infinity,
              ease: "easeInOut",
              delay: (row + col) * 0.12,
            }}
          />
        );
      })}
    </div>
  );
}

export default function PixelWaveDemo() {
  return (
    <div className="flex h-dvh w-full items-center justify-center bg-white">
      <div className="flex items-end gap-12">
        {SIZES.map(({ label, grid, pixel, gap }) => (
          <div key={label} className="flex flex-col items-center gap-4">
            <PixelGrid grid={grid} pixel={pixel} gap={gap} />
            <span className="text-sm font-medium text-[#64748B]">{label}</span>
          </div>
        ))}
      </div>
    </div>
  );
}

Update the import paths to match your project setup.

Similar screens