In my layout, I have multiple sections with a scrollbar that displays buttons using scrollspy. Everything is working perfectly except for one issue - when scrolling too far down, the scrollspy disappears off the page to the right. Is there a way to adjust the scrollbar so that it moves in the direction of the active scrollspy button (the active button receives a class active
automatically)?
It's important to note that I am not utilizing jQuery in this project.
Below is the code snippet:
window.setInterval(function(){
window.onload = function () {
document.getElementsByClassName('navbar')[0].scrollLeft = 0;
var menus = document.getElementsByClassName('nav-link');
for (var i = 0; i < menus.length; i++) {
if (menus[i].classList.contains('active')) {
document.getElementsByClassName('navbar')[0].scrollLeft = menus[i].offsetLeft;
}
}
}
}, 1);
Thank you for your assistance!