<!-- https://dribbble.com/shots/6251784-Navigation-Menu-Animation -->
<nav>
<div class="link-background"></div>
<ul>
<li>
<a class="active">
<svg>
<use xlink:href="#home">
</svg>
<span class="link-text">Home</span>
</a>
</li>
<li>
<a>
<svg>
<use xlink:href="#inbox">
</svg>
<span class="link-text">Inbox</span>
</a>
</li>
<li>
<a>
<svg>
<use xlink:href="#profile">
</svg>
<span class="link-text">Profile</span>
</a>
</li>
</ul>
</nav>
<svg style=display:none;>
<symbol version="1.1" id="home" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 50 50">
<path fill="none" stroke="" stroke-width="2" stroke-linecap="round" stroke-miterlimit="10" d="M31,44.738v-8.52
c0-1.505-0.69-2.929-1.877-3.87l0,0c-1.826-1.448-4.421-1.448-6.247,0l0,0C21.69,33.288,21,34.712,21,36.218v3.565"/>
<line fill="none" stroke="" stroke-width="2" stroke-linecap="round" stroke-miterlimit="10" x1="15" y1="20.223" x2="29" y2="20.223"/>
<path fill="none" stroke="" stroke-width="2" stroke-linecap="round" stroke-miterlimit="10" d="M8,19.232
L24.681,5.466c0.758-0.632,1.869-0.62,2.612,0.03l15.03,13.144C42.754,19.016,43,19.557,43,20.126v22.892
C43,44.113,42.105,45,41,45h-8.6H31H10c-1.105,0-2-0.887-2-1.982V28.151c0-1.095,0.895-1.982,2-1.982h7"/>
</symbol>
<symbol version="1.1" id="inbox" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 50 50">
<path fill="none" stroke-width="2" stroke-miterlimit="10" d="M45.5,39.5h-40c-1.657,0-3-1.343-3-3V23.55
c0-0.028,0.022-0.05,0.05-0.05h13.555l0.665,1.989c0.952,3.563,4.29,6.106,8.139,6.115c0.061,0,0.122,0,0.183,0
c3.849-0.009,7.187-2.552,8.139-6.115l0.665-1.989H47.45c0.028,0,0.05,0.022,0.05,0.05V37.5C47.5,38.605,46.605,39.5,45.5,39.5z"/>
<path fill="none" stroke-width="2" stroke-miterlimit="10" d="M47.5,23.5l-7.109-11.664
c-0.556-0.835-1.493-1.336-2.496-1.336H12.106c-1.003,0-1.94,0.501-2.496,1.336L2.5,23.5"/>
</symbol>
<symbol version="1.1" id="profile" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 50 50">
<line fill="none" stroke-width="2" stroke-linecap="round" stroke-miterlimit="10" x1="18.5" y1="37" x2="28.5" y2="37"/>
<line fill="none" stroke-width="2" stroke-linecap="round" stroke-miterlimit="10" x1="14.5" y1="42" x2="21.5" y2="42"/>
<path fill="none" stroke-width="2" stroke-linecap="round" stroke-miterlimit="10" d="M35.857,27.299
C32.753,25.216,29.019,24,25,24C14.735,24,6.323,31.931,5.557,42"/>
<path fill="none" stroke-width="2" stroke-linecap="round" stroke-miterlimit="10" d="M35.857,29.299"/>
<path fill="none" stroke-width="2" stroke-linecap="round" stroke-miterlimit="10" d="M39.665,30.648"/>
<path fill="none" stroke-width="2" stroke-linecap="round" stroke-miterlimit="10" d="M44.443,42
c-0.269-3.539-1.483-6.815-3.391-9.574"/>
<circle fill="none" stroke="" stroke-width="2" stroke-linecap="round" stroke-miterlimit="10" cx="25.5" cy="17" r="9"/>
</symbol>
</svg>
@import url("https://fonts.googleapis.com/css?family=Roboto:400,400i,700");
body,
html {
height: 100%;
}
body {
margin: 0;
display: flex;
align-items: center;
justify-content: center;
background: #e9ecff;
font-family: "Roboto";
}
nav {
position: relative;
}
ul {
list-style-type: none;
padding: 0;
background: #432fbf;
border-bottom-left-radius: 40px;
border-bottom-right-radius: 40px;
box-shadow: 2px 10px 20px rgba(67, 47, 191, 0.5);
}
li {
display: inline-block;
margin: 40px 20px;
}
li:first-child {
margin-left: 30px;
}
li:last-child {
margin-right: 30px;
}
a {
cursor: pointer;
display: flex;
align-items: center;
padding: 10px 25px;
}
svg {
stroke: #9386ea;
width: 44px;
height: 44px;
transform: translateX(35px);
transition: 0.4s ease all;
}
a.active {
color: white;
}
a.active svg {
stroke: white;
transform: translateX(0px);
}
.link-text {
color: white;
margin-left: 16px;
opacity: 0;
transition: 0.3s ease all;
user-select: none;
height: 42px;
display: flex;
align-items: center;
z-index: 1;
}
a.active .link-text {
opacity: 1;
transition-delay: 0.1s;
}
.link-background {
position: absolute;
left: 30px;
top: 53px;
background: #5e4ecb;
border-radius: 18px;
width: 153px;
height: 70px;
z-index: 0;
transition: 0.4s cubic-bezier(0.7, 0, 0.38, 0.86) all;
}
let links = document.querySelectorAll('a');
let background = document.querySelector('.link-background')
const clickHandler = (el) => {
links.forEach(link => {
link.classList.remove('active');
})
el.classList.add('active');
}
links.forEach((link,index) => {
link.addEventListener('click',(e) => {
e.preventDefault();
// Update background position
background.style.transform = `translateX(${128.25 * index}%)`
clickHandler(e.currentTarget);
});
})
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.