I have made a simple sidebar navigation menu with 6 elements. Here is an example of what I want:
- I click on the 1st element and the menu grows from 2vh to 4vh and changes its color (the transition).
- Then I click on the 2nd element and the 2nd element grows, while the 1st one shrinks (goes back to it original styling).
- And then if I click the 2nd element again, I want it to go back to its normal styling too. And so on with the other elements.
function scale() {
const element = document.getElementById('nav1');
element.classList.add('navmenu-clicked');
}
.navmenu {
color: #213362;
font-size: 2vh;
position: fixed;
left: 2%;
text-decoration: none;
cursor: default;
font-family: Arial, Helvetica, sans-serif;
transition: all 2s;
}
.navmenu-clicked {
color: red;
font-size: 4vh;
}
#nav1 {
top: 30%;
}
#nav2 {
top: 40%;
}
#nav3 {
top: 50%;
}
#nav4 {
top: 60%;
}
#nav5 {
top: 70%;
}
#nav6 {
top: 80%;
}
.panel1,
.panel2 {
height: 100vh;
}
.panel1 {
background-color: red;
}
.panel2 {
background-color: blue;
}
<a class="navmenu" id="nav1" href="#" onclick="scale()">menu1</a>
<a class="navmenu" id="nav2" href="#" onclick="scale()">menu2</a>
<a class="navmenu" id="nav3" href="#" onclick="scale()">menu3</a>
<a class="navmenu" id="nav4" href="#" onclick="scale()">menu4</a>
<a class="navmenu" id="nav5" href="#" onclick="scale()">menu5</a>
<a class="navmenu" id="nav6" href="#" onclick="scale()">menu6</a>
I hope I have explained it well.
Thank you!