DEV Community

Cover image for Hypnotic Spiral illusion using html css and javascript
Prince
Prince

Posted on

Hypnotic Spiral illusion using 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>Hypnotic Spiral Animation</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            background: #000;
            overflow: hidden;
            color: #fff;
        }
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .spiral {
            position: relative;
            width: 200px;
            height: 200px;
            animation: spin 4s linear infinite;
        }
        .spiral::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            border-radius: 50%;
            border: 2px solid transparent;
            border-image: conic-gradient(from 0deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
            border-image-slice: 1;
            animation: animateSpiral 10s linear infinite;
        }
        .wave {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            border-radius: 50%;
            border: 2px solid rgba(255, 255, 255, 0.3);
            animation: expandWave 1s ease-out infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        @keyframes animateSpiral {
            0%, 100% { transform: scale(1); }
            50% { transform: scale(0.5); }
        }
        @keyframes expandWave {
            0% {
                width: 0;
                height: 0;
                opacity: 1;
            }
            100% {
                width: 500px;
                height: 500px;
                opacity: 0;
            }
        }
    </style>
</head>
<body>
    <div class="spiral">
        <div class="wave"></div>
    </div>
</body>
</html>

Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
moopet profile image
Ben Sinclair

You say, "using javascript" and include the #javascript tag, but this doesn't use any at all?

Also, you call it an "illusion", but it doesn't seem to cause me any illusion-like issues. Is there supposed to be something we can see by looking at it in a certain way, or is it a straightforward pleasing-to-look-at type animation?

Collapse
 
prince_beec5ccde00b7c6c73 profile image
Prince

Ok i'll make sure it looks illusion to you ok sir