VOOZH about

URL: https://www.geeksforgeeks.org/bootstrap/bootstrap-scrollspy/

⇱ Bootstrap | Scrollspy - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap | Scrollspy

Last Updated : 28 Apr, 2022

Sometimes while designing the website, we include some attractive features which make the website eye-catching. One of the features is Bootstrap Scrollspy which targets the navigation bar contents automatically on scrolling the area. 

Example 1: Scrollspy Vertical Navigation bar

Output:

👁 Image
 


Example 2: Scrollspy Horizontal Navigation bar

Output:

👁 Image
 

Some attributes are added with the elements for the implementation of this feature. 
These are:

  1. data-spy It is an attribute that is to be added with the element which is used as the scrollable area (in the above example we are taking it as the body). 
    The value of data-spy is scroll.
  2. data-target This attribute is used to connect the navigation bar with the scrollable area. 
    It takes the value as the name of the ID or class of the navigation bar.
  3. data-offset This attribute specifies the number of pixels to offset from the top when calculating the position of the scroll.

Supported Browser:

  • Google Chrome
  • Microsoft Edge
  • Firefox
  • Opera
  • Safari
Comment
Article Tags:

Explore