Try to scroll this page and look at the navigation bar while scrolling!
...
Example Explained
To designate an element as the scrollable region, add data-spy=”scroll” to it (usually the <body> element).
Next, include the data-target attribute with the navigation bar’s class name (.navbar) or id as its value. This is to ensure that the scrollable area and the navbar are connected.
Be aware that scrollable elements (<div id=”section1″> matches <a href=”#section1″>) must match the ID of the links contained in the list items of the navbar.
When determining the scroll position, the optional data-offset attribute indicates how many pixels to offset from the top. This is helpful if you feel that the links in the navbar alter the active state when they navigate to scrollable components by changing it too soon or too early. Ten pixels is the default.
Relative positioning: In order for the element with data-spy=”scroll” to function correctly, the CSS position property must have a value of “relative”.