I was able to solve it myself.
Was only a little bit of jQuery code
If it can help anyone else here is my code:`
jQuery( document ).ready(function() {
jQuery(window).scroll(function(){
var scrollTop = jQuery(document).scrollTop();
var anchors = jQuery('body').find('.ez-toc-section');
offset_1 = 150;
offest_2 = 1;
for (var i = 0; i < anchors.length; i++){
if (scrollTop > jQuery(anchors[i]).offset().top - offset_1 && scrollTop < jQuery(anchors[i]).offset().top + jQuery(anchors[i]).height() - offest_2) {
jQuery('nav ul li a').removeClass('active');
jQuery('nav ul li a[href="#' + jQuery(anchors[i]).attr('id') + '"]').addClass('active');
}
}
});
});
You can adjust the ofset_1 and offset_2 to adjust when a new highlight should be triggered. Replace ul with ol if you have an ordered list.
Source https://stackoverflow.com/questions/65954297/highlighting-item-in-table-of-contents-when-section-is-active-on-page-as-scrolli and https://stackoverflow.com/questions/26382551/making-a-menu-class-active-when-scrolled-past
-
This reply was modified 3 years, 3 months ago by Phil.
-
This reply was modified 3 years, 3 months ago by Phil.