Animated NAVBAR



HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>tushargahora.blogspot.com</title>
    <link rel="stylesheet" href="CSSNAVBAR.css">
    <script type="module" src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.esm.js"></script>
<script nomodule src="https://unpkg.com/ionicons@7.1.0/dist/ionicons/ionicons.js"></script>
</head>
<body>
<div class="navbar">
<ul>
    <li class="list active">
        <a href="#">
            <span class="icon"><ion-icon name="home-outline"></ion-icon></span>
            <span class="text">Home</span>
            <span class="circle"></span>
        </a>
    </li>
    <li class="list">
        <a href="#">
            <span class="icon"><ion-icon name="settings-outline"></ion-icon></span>
            <span class="text">setting</span>
            <span class="circle"></span>
        </a>
    </li>
    <li class="list">
        <a href="#">
            <span class="icon"><ion-icon name="person-outline"></ion-icon></span>
            <span class="text">About us</span>
            <span class="circle"></span>
        </a>
    </li>

        <div class="indicator"></div>
</ul>
</div>
</body>
</html>



<!------------------------------------------tushargahora.blogspot.com-------------------------------------------------------------------------------------------------->

JavaScript:

const list = document.querySelectorAll('.list');

function activeLink() {
    list.forEach((item) =>
    item.classList.remove('active'));
    this.classList.add('active');
}

 list.forEach((item) =>
 item.addEventListener('click', activeLink));

CSS:

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800;900&display=swapdisplay=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins' , sans-serif;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    /* background:  #06021b; Black */
    background:  #FFF;
}

.navbar {
    position: relative;
    width: 230px;
    height: 70px;
    /* background: linear-gradient(45deg, #2196f3, #e91e63); blue-pink */
    background: #000000;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 10px;
}

.navbar ul {
    display: flex;
    width: 350px;
}

.navbar ul li {
    position: relative;
    width: 70px;
    height: 70px;
    list-style: none;
    z-index: 1;

}

.navbar ul li a {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    width: 100%;
    text-align: center;
    font-weight: 500;
   
}

.navbar ul li a .icon {
    position: relative;
    display: block;
    line-height: 75px;
    font-size: 1.5em;
    text-align: center;
    color:white;

}
.navbar ul li.active a .icon {
    transform: translateY(-32px);
    transition: .5s;
    color: #000000;
}
.navbar ul li a .text{
    position: absolute;
    color: white;
    font-size: .75em;
    font-weight: 400;
    letter-spacing: .05em;
    opacity: 0;
    transform: translateY(20px);
    transition: .5s;
}

.navbar ul li.active a .text {
    opacity: 1;
    transform: translateY(10px);
}


.navbar ul li a .circle {
    position: absolute;
    display: block;
    width: 50px;
    height: 50px;
    background:transparent ;
    border-radius:50%;
    /* border: 1.8px solid #fff ; */
    /* box-shadow:0px 0px 40px 1px #48abe0; */
    /* box-shadow:0px 0px 40px 1px #cd9292; */
    box-shadow:0px 0px 40px 1px #FBE5E5;
    transform: translateY(-37px) scale(0);
}

.navbar ul li.active a .circle{
    transition: .5s;
    transition-delay: .5s;
    transform: translateY(-37px) scale(1);
}

.indicator {
    position: absolute;
    top: -50%;
    width: 70px;
    height: 70px;
    /* background: linear-gradient(45deg, #2196f3, #e91e63);blue-pink */
    background: #FBE5E5;
    /* border: 6px  solid #06021b; black */
     border: 6px  solid #FFF;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: .5s;

}

.indicator::before {
    content: '';
    position: absolute;
    top: 50%;
    left: -22px;
    width: 20px;
    height: 20px;
    background-color: transparent;
    border-top-right-radius: 20px;
    /* box-shadow: 1px -10px 0 #06021b; black */
     box-shadow: 1px -10px 0 #fff;
/* COPYRIGHTS: "http://tushargahora.blogspot.com/" */
}
.indicator::after {
    content: '';
    position: absolute;
    top: 50%;
    right: -22px;
    width: 20px;
    height: 20px;
    background-color: transparent;
    border-top-left-radius: 20px;
    /* box-shadow: -1px -10px 0 #06021b;black */
    box-shadow: -1px -10px 0 #fff;

}

.navbar ul li:nth-child(1).active~.indicator {
    transform: translateX(calc(70px * 0));
}

.navbar ul li:nth-child(2).active~.indicator {
    transform: translateX(calc(70px * 1));
}

.navbar ul li:nth-child(3).active~.indicator {
    transform: translateX(calc(70px * 2));
}

.navbar ul li:nth-child(4).active~.indicator {
    transform: translateX(calc(70px * 3));
}


Output: https://codepen.io/TusharGahora/full/vYmLxWm


No comments:

Powered by Blogger.