DEV Community

0 seconds of 21 secondsVolume 90%
Press shift question mark to access a list of keyboard shortcuts
00:00
00:00
00:21
 
Prince
Prince

Posted on

2

BLACK HOLE ANIMATION WITH HTML CSS AND JAVASCRIPT

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Black Hole Animation</title>
  <style>
    body {
      margin: 0;
      overflow: hidden;
      background: radial-gradient(ellipse at center, black, #1a1a1a);
      height: 100vh;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .black-hole-container {
      position: relative;
      width: 300px;
      height: 300px;
    }

    .black-hole {
      position: absolute;
      bottom: 20px;
      left: 50%;
      width: 200px;
      height: 200px;
      background: black;
      border-radius: 50%;
      border: 10px solid transparent;
      /* background-image: conic-gradient(pink 0% 33%, purple 33% 66%, blue 66% 100%); */
      box-shadow: 
        0 0 20px 5px pink,
        0 0 40px 10px purple,
        0 0 60px 15px blue;
      animation: neon-glow 3s infinite ease-in-out;
      transform: translateX(-50%);
    }

    .purple-shadow {
      position: absolute;
      top: 30px;
      left: 50%;
      width: 450px;
      height: 450px;
      background: radial-gradient(circle, rgba(128, 0, 128, 0.2), transparent 70%);
      border-radius: 50%;
      transform: translate(-50%);
      animation: wave-color-motion 5s infinite ease-in-out;
    }

    .stars {
      position: absolute;
      width: 100%;
      height: 100%;
      z-index: -1;
    }

    .star {
      position: absolute;
      width: 4px;
      height: 4px;
      background: purple;
      border-radius: 50%;
      animation: twinkle 3s infinite ease-in-out;
    }

    /* Animations */
    @keyframes neon-glow {
      0%, 100% {
        box-shadow: 
          0 0 20px 5px pink,
          0 0 40px 10px purple,
          0 0 60px 15px blue;
      }
      50% {
        box-shadow: 
          0 0 30px 10px pink,
          0 0 50px 15px purple,
          0 0 70px 20px blue;
      }
    }

    @keyframes wave-color-motion {
      0% {
        transform: translate(-50%) scale(1);
        background: radial-gradient(circle, rgba(59, 3, 59, 0.2), transparent 70%);
      }
      25% {
        transform: translate(-50%) scale(1.1);
        background: radial-gradient(circle, rgba(170, 0, 170, 0.4), transparent 70%);
      }
      50% {
        transform: translate(-50%) scale(1.2);
        background: radial-gradient(circle, rgba(200, 0, 200, 0.6), transparent 70%);
      }
      75% {
        transform: translate(-50%) scale(1.1);
        background: radial-gradient(circle, rgba(170, 0, 170, 0.4), transparent 70%);
      }
      100% {
        transform: translate(-50%) scale(1);
        background: radial-gradient(circle, rgba(128, 0, 128, 0.2), transparent 70%);
      }
    }

    @keyframes twinkle {
      0%, 100% {
        opacity: 1;
      }
      50% {
        opacity: 0.2;
      }
    }
  </style>
</head>
<body>
  <div class="black-hole-container">
    <div class="purple-shadow"></div>
    <div class="black-hole"></div>
  </div>
  <div class="stars"></div>

  <script>
    const starsContainer = document.querySelector('.stars');

    // Generate random stars
    for (let i = 0; i < 200; i++) {
      const star = document.createElement('div');
      star.classList.add('star');
      star.style.left = `${Math.random() * 100}vw`;
      star.style.top = `${Math.random() * 100}vh`;
      star.style.animationDelay = `${Math.random() * 5}s`;
      starsContainer.appendChild(star);
    }
  </script>
</body>
</html>

Enter fullscreen mode Exit fullscreen mode

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay