In my Javascript code I'm listening for the scroll event and doing some work whenever it fires:
document.addEventListener(
'scroll',
(event) => {
// do something
},
{ passive: true }
);
I have a nav bar which contains anchors to different sections on my page, which when clicked causes the page to scroll down to the section (and fires the scroll event):
<nav class="navbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link nav-link-jump" href="#anchor-1">Popular Items</a>
</li>
</ul>
</nav>
...
<section id="anchor-1">...</section>
However, I do not want the scroll event to fire when the page scrolls as a result of clicking on the anchor link. I only want it to fire when the user actually scrolls (i.e. with mouse wheel or by swiping).
I couldn't find any field in the 'event' object that would differentiate the two scroll sources but perhaps I missed something.