I am trying to keep the link hover effect in place after clicking. This is what I currently have:
HTML:
<div class="nav-desktop">
<ul class="desktop-list">
<li class="desktop-link"><a class="link is-active" href="index.html">Home</a></li>
<li class="desktop-link"><a class="link" href="html/about.html">About</a></li>
<li class="desktop-link"><a class="link" href="html/blog.html">Blog</a></li>
<li class="desktop-link"><a class="link" href="html/projects.html">Projects</a></li>
<li class="desktop-link"><a class="link" href="html/contact.html">Contact</a></li>
</ul>
</div>
CSS:
.link {
color: var(--dracula-pink);
padding: 5px 5px 5px 5px;
margin-right: 5rem;
text-decoration: none;
font-size: 1.2rem;
text-transform: uppercase;
text-shadow: 0 2px 3px rgba(0, 0, 0, 0.4), 0 8px 13px rgba(0, 0, 0, 0.1), 0 18px 23px rgba(0, 0, 0, 0.1);
}
.link:hover {
background-repeat: repeat-x;
background-position: left 0% bottom -5%;
background-image: linear-gradient(90deg, rgba(139, 233, 253, 1) 0%, rgba(189, 147, 249, 1) 50%, rgba(80, 250, 123, 1) 100%);
background-size: 100% 18%;
transition: ease-in 0.2s;
}
.link.is-active {
background-repeat: repeat-x;
background-position: left 0% bottom -5%;
background-image: linear-gradient(90deg, rgba(139, 233, 253, 1) 0%, rgba(189, 147, 249, 1) 50%, rgba(80, 250, 123, 1) 100%);
background-size: 100% 18%;
}
JS:
const link = document.querySelector(".link");
link.addEventListener("click", toggleActive);
function toggleActive() {
link.classList.toggle("is-active");
};
I know I will have to add something to remove the effect from the previous link, but I can't even get this part down after every variation I can think of.