How can I dynamically add the "active" class to a link based on which section it has scrolled to?
I want the active state to be applied without a hover effect, only when the corresponding section is currently in view.
#pagemenu{
display: block;
position: fixed;
top: 40%;
font-size: 12px;
text-transform: uppercase;
}
#pagemenu ul{
list-style: none;
display: block;
margin-left: 0;
}
.pagelink{
display: block;
height: 38px;
width: 200px;
margin-bottom: 6px;
border-left: 2px solid red;
color: red;
padding-left: 10px;
padding-top: 10px;
}
.active2{
background-color: #424242;
border-left: 2px solid #e1b130;
color: #e1b130;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="pagemenu">
<a class="pagelink active2" href="#">Link Here</a>
<a class="pagelink" href="#">Link Here</a>
<a class="pagelink" href="#">Link Here</a>
<a class="pagelink" href="#">Link Here</a>
</div>