How to reproduce:
Open the template Agency
Set to Bootstrap 5.2 (default)
Open Preview
Click any other anchor link than the 1st (= SERVICES)
Notice how SERVICES remains active (yellow), altho it should turn yellow off for SERVICES and turn yellow on for the anchor link you clicked.
Example, where I’ve clicked on About:
This post may shed some light. I posted a link to a discussion on Github about Bootstrap 5.2 and scrollspy that you may want to read.
It seems like Scrollspy activates the links in a very erratic manner. I’ve made a test site here. .
Clicking the menu links activates the links correctly, but (on a widescreen 24" monitor) clicking Forth Section link activates the Fifth Section link in the Navbar.
Scrolling all the way to the bottom of the footer and then scrolling back up into the Sixth Section never activates the Sixth Section link. If you scroll to the bottom of the footer and then click the Sixth Section link, it will scrol…
I see… So it’s a non-solved bug in Bootstrap 5.2 regarding Scrollspy. Bummer.
I’ve noticed when opening the template as Bootstrap 4.6 - all is fine indeed.
Since my project is already saved as Bootstrap 5.2, and appears to be locked, there’s no way to change it to back to Bootstrap 4.6.
Can I somehow copy/paste my original project in total into a new Bootstrap 4.6 Agency template?
@ferdesign
Je kunt je eigen scrollspy maken
Verwijder op de body-tag de attributen:
data-bs-spy="scroll"
data-bs-target="#mainNav"
data-bs-offset="54"
Voeg dit script toe aan een javascript-bestand
(function () {
'use strict';
// constants
const sections = [...document.querySelectorAll('section[id]')];
const menuLinks = [...document.querySelectorAll('.nav-item a')];
const navoffset = document.getElementById('mainNav').clientHeight;
const navToggle = document.querySelector('.navbar-toggler');
// Scrollspy handler
const scrollHandle = () => {
const scrollPosition = document.documentElement.scrollTop || document.body.scrollTop;
menuLinks.forEach((link) => link.classList.remove('active'));
sections.forEach((section) => {
const offset = section.offsetTop - navoffset;
if (offset <= scrollPosition) {
menuLinks.forEach((link) => link.classList.remove('active'));
const target = document.querySelector(`a[href="#${section.id}"]`);
if (!target.hash) return;
target.classList.add('active');
if (target.parentElement.classList.contains('dropdown-menu')) {
target.parentElement.parentElement.firstChild.classList.add('active');
}
if (document.querySelector('#navbarResponsive').classList.contains('show')) navToggle.click();
}
});
};
// event listeners
document.addEventListener('scroll', scrollHandle, false);
document.addEventListener('resize', scrollHandle, false);
document.addEventListener('readystatechange', scrollHandle, false);
})();
Nu heb je een scrollspy die werkt zoals het werkte voordat Bootstrap hun scrollspy veranderde in 5.2
1 Like
Thanks (dank je!) , ik ga dit vanavond proberen en laat het je weten wanneer het gelukt is
@kuligaposten Works perfectly: https://onetagger.github.io
And easy workaround, thank to you
1 Like