Skip to content
Advertisements

JavaScript Menu Animation

CODEPEN:

JavaScript Menu Animation

HTML CODE:

 <div class="container">
        <div id="top"></div>
        <div id="center"></div>
        <div id="bottom"></div>
    </div>

CSS CODE:

body{
    height: 100vh;
    background: linear-gradient(to bottom left, #000000, #262626, #1d1d1d );
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}
.container{
    width: 200px;
    height: 180px;
    position: relative;
    cursor: pointer;
}
#top {
    position: absolute;
    top: 0;
    left: 0;
    width: 50%;
    height: 36px;
    background: linear-gradient(to bottom left,#783b00, #825000, #c15f00);
    transition: 1s;
    border-radius: 20px 0px 0px 0px;
}
#center {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    width: 100%;
    height: 36px;
    background: linear-gradient(to bottom left,#783b00, #825000, #c15f00);
    transition: 1s;
}
#bottom {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 50%;
    height: 36px;
    background: linear-gradient(to bottom left,#783b00, #825000, #c15f00);
    transition: 1s;
    border-radius: 0px 0px 20px 0px;
}
.container.active #center {
    border-radius: 50%;
    background: transparent;
    border: 5px solid #c15f00;
    width: 50px;
    height: 50px;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%) scale(6);
}
.container.active #top {
    transform: rotate(45deg);
    width: 120%;
    top: 70px;
    left: -20px;
    border-radius: 50px;
}
.container.active #bottom {
    transform: rotate(-45deg);
    width: 120%;
    right: -20px;
    bottom: 70px;
    border-radius: 50px;
}

JS CODE:


        let box = document.querySelector(".container");

        box.addEventListener("click", function () {
            box.classList.toggle("active");
            document.querySelector("body").classList.toggle("bcolor")
        })
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: