Struggling to implement a navigation menu within a self-scrolling div using html/css/jquery. Looking for the menu items to toggle the active class when in view or at the top of the scrolling div.
I'm essentially trying to achieve something like this example: https://codepen.io/vlrprbttst/pen/LkjZbE?editors=1010, but contained within a self-scrolling div.
I've made progress with this code pen: https://codepen.io/frontend2020/pen/ExWaXVE, however, the active class triggers prematurely and I can't seem to pinpoint why.
I suspect there may be an issue in the following section of code:
if (
refElement.position().top <= scrollPos &&
refElement.position().top + refElement.height() > scrollPos
)
I've checked the scroll position and element positions, everything seems aligned, yet I feel I might be overlooking something crucial.
Any guidance or solution would be greatly appreciated. Thank you!