<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Background Animation</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="container" id="container"></div>
    <script src="script.js"></script>
</body>
</html>
body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
}

.container {
    position: relative;
    width: 100%;
    height: 100%;
    background-image: linear-gradient(orange, black);
    background-color: #000;
}

.bubble {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: rgba(255, 0, 0, 0.5);
    border-radius: 50%;
    animation: float cubic-bezier(0.215, 0.610, 0.355, 1) infinite;
}

@keyframes float {
    0% {
        transform: translateY(0) rotate(0);
    }
    40% {
        border: 2px yellow;
    }
    70% {
        background-image: radial-gradient(rgb(255, 230, 0), red);
    }
    100% {
        transform: translateY(100vh) rotate(360deg);
        background-color: yellow;
        width: 40px;
        height: 40px;
    }
}
document.addEventListener("DOMContentLoaded", function() {
    const container = document.getElementById("container");
    const numberOfBubbles = 250;

    // Create bubbles
    for (let i = 0; i < numberOfBubbles; i++) {
        createBubble();
    }

    // Function to create a bubble
    function createBubble() {
        const bubble = document.createElement("div");
        bubble.classList.add("bubble");
        bubble.style.left = Math.random() * 100 + "vw";
        bubble.style.animationDuration = (Math.random() * 6 + 3) + "s";
        container.appendChild(bubble);
    }

    // Intensify bubbles on mouseover
    container.addEventListener("mousemove", function(event) {
        const bubbles = document.querySelectorAll(".bubble");
        bubbles.forEach(bubble => {
            const bubbleRect = bubble.getBoundingClientRect();
            const mouseX = event.clientX;
            const mouseY = event.clientY;

            const distance = Math.sqrt(
                Math.pow(mouseX - (bubbleRect.left + bubbleRect.width / 2), 2) +
                Math.pow(mouseY - (bubbleRect.top + bubbleRect.height / 2), 2)
            );

            const maxDistance = Math.sqrt(
                Math.pow(window.innerWidth, 2) + Math.pow(window.innerHeight, 2)
            );

            const intensity = 1 - (distance / maxDistance);

            bubble.style.transform = "scale(" + intensity + ")";
        });
    });
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.