Meteor Effect
A group of beams in the background of a container, sort of like meteors.
Meteors because they're cool
I don't know what to write so I'll just paste something cool here. One more sentence because lorem ipsum is just unacceptable. Won't ChatGPT the shit out of this.
Installation
Install dependencies
npm i motion clsx tailwind-merge
Add util file
import { ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}
Add the animation to your CSS
@theme inline {
--animate-meteor-effect: meteor 5s linear infinite;
@keyframes meteor {
0% {
transform: rotate(215deg) translateX(0);
opacity: 1;
}
70% {
opacity: 1;
}
100% {
transform: rotate(215deg) translateX(-500px);
opacity: 0;
}
}
}
Copy the source code
components/ui/meteors.tsx
"use client";
import { cn } from "@/lib/utils";
import { motion } from "framer-motion";
import React from "react";
export const Meteors = ({
number,
className,
}: {
number?: number;
className?: string;
}) => {
const meteors = new Array(number || 20).fill(true);
return (
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
transition={{ duration: 0.5 }}
>
{meteors.map((el, idx) => {
const meteorCount = number || 20;
// Calculate position to evenly distribute meteors across container width
const position = idx * (800 / meteorCount) - 400; // Spread across 800px range, centered
return (
<span
key={"meteor" + idx}
className={cn(
"animate-meteor-effect absolute h-0.5 w-0.5 rotate-[45deg] rounded-[9999px] bg-slate-500 shadow-[0_0_0_1px_#ffffff10]",
"before:absolute before:top-1/2 before:h-[1px] before:w-[50px] before:-translate-y-[50%] before:transform before:bg-gradient-to-r before:from-[#64748b] before:to-transparent before:content-['']",
className,
)}
style={{
top: "-40px", // Start above the container
left: position + "px",
animationDelay: Math.random() * 5 + "s", // Random delay between 0-5s
animationDuration: Math.floor(Math.random() * (10 - 5) + 5) + "s", // Keep some randomness in duration
}}
></span>
);
})}
</motion.div>
);
};
Props
Prop name | Type | Description |
---|---|---|
className | string | The class name of the child component. |
number | number | The number of meteors you want in the card |
Build websites faster and 10x better than your competitors with Aceternity UI Pro
With the best in class components and templates, stand out from the crowd and get more attention to your website. Trusted by founders and entrepreneurs from all over the world.
Manu is an artist, I didn't know what I wanted when we started, but his
intuition and eye for design more than made up for it. We went from "I
want something dark theme and high...
John Ferry
President at TAC, CEO at Rogue