Sometimes while designing the website, we include some attractive features which makes website eye-catching. One of the features is Bootstrap scrollspy which target the navigation bar contents automatically on scrolling the area.
Example 1 : Scrollspy Vertical Navigation bar
Example 2 : Scrollspy Horizontal Navigation bar
Some attributes are added with the elements for the implementation of this feature.
These are –
- data-spy It is an attribute that is to be added with the element which is using as the scrollable area (in the above example we are taken it as the body).
The value of data-spy is scroll.
- data-target This attribute is used to connect navigation bar with the scrollable area.
It takes the value as the name of the ID or class of the navigation bar.
- data-offset This attribute specifies the number of pixels to offset from top when calculating the position of scroll.
Note: A default value of “data-offset” is taken as 10 pixels. It is an optional attribute.
- Bootstrap 4 | Scrollspy
- Include Bootstrap in AngularJS using ng-bootstrap
- What's new in Bootstrap v4.3 ?
- Bootstrap 4 | Pagination
- Bootstrap 4 | Collapse
- Bootstrap 4 | Colors
- Bootstrap 4 | Dropdowns
- Bootstrap 4 | Introduction
- Bootstrap 4 | Typography
- Bootstrap | Tables | Set-2
- Bootstrap | Tables | Set-1
- Typography in Bootstrap
- Bootstrap | Spinners Set-1
- Bootstrap | Spinners Set-2
- Bootstrap 4 | Nav-pills
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.