I have a sidebar that allows me to snap to content on the main part of the page. The sidebar sticks to the page as the user scrolls down
<div class="sidebar" style="width: 16%;float: left;position: absolute;margin-top:15px;">
<div class="jump_stage" onclick="window.location.href='#div1'">div1</div>
<div class="jump_stage" onclick="window.location.href='#div2'">div2</div>
<div class="jump_stage" onclick="window.location.href='#div3'">div3</div>
<div class="jump_stage" onclick="window.location.href='#div4'">div4</div>
<div class="jump_stage" onclick="window.location.href='#div5'">div5</div>
</div>
<div class="main_body">
<div id="div1" class="content">Div 1 content</div>
<div id="div2" class="content">Div 2 content</div>
<div id="div3" class="content">Div 3 content</div>
<div id="div4" class="content">Div 4 content</div>
<div id="div5" class="content">Div 5 content</div>
</div>
I want to add an active class (or something similar) to the sidebar when the page reaches the div. I have no idea where to start, and searching for it has brought me no luck so far.
Would I have to work out the height of the page and each element and add the class when the scroll reaches a specific number? Any help would be greatly appreciated!