Skip to content

Commit

Permalink
Merge pull request #70 from ComputerSocietyVITC/stars
Browse files Browse the repository at this point in the history
revamp: revamped stars background
  • Loading branch information
OneRandom1509 authored Aug 15, 2024
2 parents 4b84d60 + 27a588d commit d32a6d7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Footer from "../components/footer/Footer";
import type { Metadata } from "next";
import "./globals.css";
import "./stars.css";
import Stars from "@/components/stars/stars";
import { FloatingNav } from "@/components/navbar/FloatingNav";

export const metadata: Metadata = {
Expand Down Expand Up @@ -40,9 +40,7 @@ export default function RootLayout({
return (
<html lang="en" className="scroll-smooth overflow-x-hidden bg-black">
<body className="bg-[url('/bg.svg')] bg-cover">
<div id="stars"></div>
<div id="stars-2"></div>
<div id="stars-3"></div>
<Stars starCount={130} />
<FloatingNav navItems={navItems} />
{children}
<Footer />
Expand Down
25 changes: 25 additions & 0 deletions src/components/stars/stars.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@keyframes starAnimation {
from {
transform: translateY(100vh);
opacity: 1;
}
to {
transform: translateY(-100vh);
opacity: 0;
}
}

.stars {
position: fixed;
width: 100%;
height: 100%;
z-index: 0; /* Behind all content */
overflow: hidden;
}

.star {
position: absolute;
background-color: white;
border-radius: 50%;
animation: starAnimation linear infinite;
}
37 changes: 37 additions & 0 deletions src/components/stars/stars.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use client";
import { useEffect } from "react";
import styles from "./stars.module.css";

interface StarsProps {
starCount?: number;
}

const Stars: React.FC<StarsProps> = ({ starCount = 50 }) => {
useEffect(() => {
const starsContainer = document.getElementById("stars-container");

if (starsContainer) {
for (let i = 0; i < starCount; i++) {
const star = document.createElement("div");
star.className = styles.star;

const size = `${Math.random() * 2 + 1}px`;
star.style.width = size;
star.style.height = size;

star.style.left = `${Math.random() * 100}%`;
star.style.top = `${Math.random() * 100}vh`;

// Random animation duration between 20 and 40s
star.style.animationDuration = `${Math.random() * 20 + 20}s`;

star.style.animationDelay = "0s";
starsContainer.appendChild(star);
}
}
}, [starCount]);

return <div id="stars-container" className={styles.stars}></div>;
};

export default Stars;

0 comments on commit d32a6d7

Please sign in to comment.