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
- How to set the offset property for ScrollSpy in Bootstrap ?
- Difference between bootstrap.css and bootstrap-theme.css
- Include Bootstrap in AngularJS using ng-bootstrap
- Difference between Bootstrap 4 and Bootstrap 5
- Difference Between Bootstrap 3 and Bootstrap 4
- What's new in Bootstrap v4.3 ?
- Bootstrap 4 | Spinners
- Bootstrap 4 | Cards
- Bootstrap 4 | Tables
- Bootstrap 4 | Jumbotron
- Bootstrap 4 | Badges
- Bootstrap 4 | Alerts
- Bootstrap 4 | Images
- Bootstrap 4 | Navs
- Bootstrap 4 | Dropdowns
- Bootstrap 4 | Introduction
- Bootstrap 4 | Typography
- Bootstrap 4 | Accordian
- Bootstrap 4 | Navigation Bar
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.