ScrollSpy listens to the scroll event and compares the scroll position with the positions of the target sections. It then updates the active class on the navigation links accordingly.
ScrollSpy should be initialized on the scrolling container (like document.body) with the target option pointing to the navigation element's selector. The target must be a selector string for the nav element, not the sections.
ScrollSpy adds the active class to the navigation link that matches the section currently visible in the viewport, typically changing its color or style to show it is active.
href attribute of navigation links to find target sections. What selector does it use internally to find these sections?ScrollSpy reads the href attribute of nav links, which should be an ID selector like #section1, and uses document.querySelector to find the corresponding section.
Adding aria-current="true" to the active link helps screen readers announce which section is currently active, improving navigation clarity for users relying on assistive technology.
