Click Navigation


<!DOCTYPE html>
<html>
<head>
<title>Navigation</title>
</head>
<body>
<nav>
<div id="marker"></div>
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Portfolio</a>
<a href="#">Team</a>
<a href="#">Contact Us</a>
</nav>
<script type="text/javascript">
var marker = document.querySelector('#marker');
var item = document.querySelectorAll('nav a');
function indicator(e) {
marker.style.left = e.offsetLeft+"px";
marker.style.width = e.offsetWidth+"px";
}
item.forEach(link => {
link.addEventListener('click' , (e)=>{
indicator(e.target);
})
})
</script>
</body>
</html>
<style type="text/css">
*{margin: 0px;padding: 0px;box-sizing: border-box;font-family: airial;}
body{display: flex; justify-content: center; -ms-align-items: center; align-items: center; min-height: 100vh;}
nav{position: relative; display: flex;}
nav a{position: relative; margin: 0px 20px; font-size: 2em; color: #000; text-decoration: none;}
nav #marker{position: absolute; height: 4px; width: 0; left: 0px; background: #000; bottom: -8px; transition: 0.5s; border-radius: 4px;}
</style>

Comments

Popular posts from this blog

Right click disable

Moutain

Input Placeholder