Bootstrap Scrollspy - Bootstrap Tutorial
Bootstrap Scrollspy
- Scrollspy is used to automatically update links in a navigation list based on scroll position.
- If you’re building our JavaScript from source, it requires util.js.
- It must be used on a Bootstrap nav component or list group. It requires position: relative; on the element you’re spying on, usually the <body>.
- When spying on elements other than the <body>, be sure to have a height set and overflow-y: scroll; applied.
- Anchors (<a>) are required and must point to an element with that id.
- When successfully implemented, your nav or list group will update accordingly, moving the .active class from one item to the next based on their associated targets.
Sample Code
Output
Bootstrap Scrollspy Nested nav
- Scrollspy also works with nested .navs. If a nested .nav is .active, its parents will also be .active.
- Scroll the area next to the navbar and watch the active class change.
Sample Code
Output
Bootstrap Scrollspy List group
- Scrollspy also works with .list-groups. Scroll the area next to the list group and watch the active class change.
Sample Code
Output
Bootstrap Scrollspy Simple anchors
- Scrollspy is not limited to nav components and list groups, so it will work on any <a> anchor elements in the current document. Scroll the area and watch the .active class change.