I have a navbar which navigates to some block. When I click several times on button , after scrolling me to correct div, when I try to scroll up by myself , the scroll event form navigation bar scrolls me to the div as much time as I have clicked to nav item.
function goToByScroll(id) {
closeSidebar();
const elem = $("body").find(`[data-el=${id}]`);
$('html, body').animate({
scrollTop: $(elem).offset().top
}, 600);
return false;
}
$("#mySidenav > a, #mySidenavMob > a, a").click(function (e) {
// e.preventDefault();
const dataAtrr = $(this).attr("data-id");
if (dataAtrr) goToByScroll(dataAtrr);
});
How should I avoid that ?