The Bootstrap Scrollspy plugin is for auto updating nav which allows you to target based (sections of the page) on scroll position. The .active class change while scrolling the page under the navbar. Sub items of the dropdown will be highlighted as well.
If you want to implement functionality of this plugin individually, simple include the scrollspy.js file along the other JS files. Else as we have discussed in the tutorial of Bootstrap Plugin Overview, you can include bootstrap.js or the minified bootstrap.min.js.
Via data attributes
You can easily add scrollspy behavior to your topbar navigation. Add data-spy=”scroll” to the element you want to spy on (typically the body). Then add attribute data-target with the ID or class of the parent element of any Bootstrap .nav component. Yu must have element or tag in the body area of the page that should have same IDs with the links that you are spring on.
Navbar links must have resolvable id targets. For example, a home must correspond to something in the DOM like
Example of Bootstrap Scrollspy Plugin
Use this code to check to use of scrollspy plugin via data attributes:
||Data attribute name
||Pixels to offset from top when calculating position of scroll.
See the use of .scrollspy(‘refresh’) method
Following table lists the events to work with scrollspy. This event may be used to hook into the function.
Event name: activate.bs.scrollspy
This event fires whenever a new item becomes activated by the scrollspy.
See the following example to use of activate.bs.scrollspy event: