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
- Difference between bootstrap.css and bootstrap-theme.css
- Include Bootstrap in AngularJS using ng-bootstrap
- What's new in Bootstrap v4.3 ?
- Bootstrap 4 | Navigation Bar
- Bootstrap 4 | Colors
- Bootstrap 4 | Tables
- Bootstrap 4 | Navs
- Bootstrap 4 | Tooltip
- Bootstrap 4 | Buttons
- Bootstrap 4 | Popover
- Bootstrap 4 | Dropdowns
- Bootstrap | Tables | Set-2
- Bootstrap | Tables | Set-1
- Typography in Bootstrap
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.