📜  如何在Bootstrap中设置ScrollSpy的offset属性?

📅  最后修改于: 2021-05-25 16:05:50             🧑  作者: Mango

偏移量是Bootstrap Scrollspy属性,在计算滚动位置时,用户可以指定要从顶部偏移的像素。当用户感到导航栏或列表较早更改状态或在冲浪时不需要时,此功能将变得很有用。它始终是一个数字,默认值为10。可以通过JavaScript更改该值,也可以将数据偏移量值放在body标签中。

句法:

  • 正常声明
    (body data-offset="")
  • JavaScript声明
    $(document).ready(function(){
      $('body').scrollspy({target: " ", offset: });
    });
    

示例1:本示例描述了引导导航栏,其中使用了四个部分,并且使用JavaScript将offset属性设置为60。



  

  Bootstrap offset property
  
  
  
  
  
    
  

  

  
  
  
    

Section 1

    
    

      GeeksforGeeks is a computer science       portal. It was created with a goal       in mind to provide well written, well       thought and well explained solutions       for selected questions. The core team       of five super geeks constituting of       technology lovers and computer science       enthusiasts have been constantly working       in this direction.       GeeksforGeeks is a computer science       portal. It was created with a goal       in mind to provide well written, well       thought and well explained solutions       for selected questions. The core team       of five super geeks constituting of       technology lovers and computer science       enthusiasts have been constantly working       in this direction.     

  
  
    

Section 2

    
    

      GeeksforGeeks is a computer science       portal. It was created with a goal       in mind to provide well written, well       thought and well explained solutions       for selected questions. The core team       of five super geeks constituting of       technology lovers and computer science       enthusiasts have been constantly working       in this direction.       GeeksforGeeks is a computer science       portal. It was created with a goal       in mind to provide well written, well       thought and well explained solutions       for selected questions. The core team       of five super geeks constituting of       technology lovers and computer science       enthusiasts have been constantly working       in this direction.     

  
  
    

Section 3

    
    

      GeeksforGeeks is a computer science       portal. It was created with a goal       in mind to provide well written, well       thought and well explained solutions       for selected questions. The core team       of five super geeks constituting of       technology lovers and computer science       enthusiasts have been constantly working       in this direction.       GeeksforGeeks is a computer science       portal. It was created with a goal       in mind to provide well written, well       thought and well explained solutions       for selected questions. The core team       of five super geeks constituting of       technology lovers and computer science       enthusiasts have been constantly working       in this direction.     

  
  
    

Section 4

    
    

      GeeksforGeeks is a computer science       portal. It was created with a goal       in mind to provide well written, well       thought and well explained solutions       for selected questions. The core team       of five super geeks constituting of       technology lovers and computer science       enthusiasts have been constantly working       in this direction.       GeeksforGeeks is a computer science       portal. It was created with a goal       in mind to provide well written, well       thought and well explained solutions       for selected questions. The core team       of five super geeks constituting of       technology lovers and computer science       enthusiasts have been constantly working       in this direction.     

     
     

输出:

示例2:该示例描述了引导列表组,其中使用了三个部分,并且body标记中的offset属性设置为15。



  

  
  
  
  Bootstrap 4 ScrollSpy
  
  
  
  
  
  
    
  

  

    
  
    

Bootstrap Scrollspy

    
    
      
        
          Section One                      Section Two                      Section Three                    
      
      
        
          

Section One

          

            GeeksforGeeks is a computer science portal. It was created with a goal             in mind to provide well written, well thought and well explained solutions             for selected questions. The core team of five super geeks constituting of             technology lovers and computer science enthusiasts have been constantly              working in this direction. GeeksforGeeks is a computer science portal.              It was created with a goal in mind to provide well written, well thought              and well explained solutions for selected questions. The core team of five             super geeks constituting of technology lovers and computer science              enthusiasts have been constantly working in this direction.              GeeksforGeeks is a computer science portal. It was created with a goal             in mind to provide well written, well thought and well explained solutions             for selected questions. The core team of five super geeks constituting of             technology lovers and computer science enthusiasts have been constantly              working in this direction. GeeksforGeeks is a computer science portal.              It was created with a goal in mind to provide well written, well thought              and well explained solutions for selected questions. The core team of five             super geeks constituting of technology lovers and computer science              enthusiasts have been constantly working in this direction.           

        
        
        
          

Section Two

          

            GeeksforGeeks is a computer science portal. It was created with a goal             in mind to provide well written, well thought and well explained solutions             for selected questions. The core team of five super geeks constituting of             technology lovers and computer science enthusiasts have been constantly              working in this direction. GeeksforGeeks is a computer science portal.              It was created with a goal in mind to provide well written, well thought              and well explained solutions for selected questions. The core team of five             super geeks constituting of technology lovers and computer science              enthusiasts have been constantly working in this direction.             GeeksforGeeks is a computer science portal. It was created with a goal             in mind to provide well written, well thought and well explained solutions             for selected questions. The core team of five super geeks constituting of             technology lovers and computer science enthusiasts have been constantly              working in this direction. GeeksforGeeks is a computer science portal.              It was created with a goal in mind to provide well written, well thought              and well explained solutions for selected questions. The core team of five             super geeks constituting of technology lovers and computer science              enthusiasts have been constantly working in this direction.           

        
        
        
          

Section Three

          

            GeeksforGeeks is a computer science portal. It was created with a goal             in mind to provide well written, well thought and well explained solutions             for selected questions. The core team of five super geeks constituting of             technology lovers and computer science enthusiasts have been constantly              working in this direction. GeeksforGeeks is a computer science portal.              It was created with a goal in mind to provide well written, well thought              and well explained solutions for selected questions. The core team of five             super geeks constituting of technology lovers and computer science              enthusiasts have been constantly working in this direction.             GeeksforGeeks is a computer science portal. It was created with a goal             in mind to provide well written, well thought and well explained solutions             for selected questions. The core team of five super geeks constituting of             technology lovers and computer science enthusiasts have been constantly              working in this direction. GeeksforGeeks is a computer science portal.              It was created with a goal in mind to provide well written, well thought              and well explained solutions for selected questions. The core team of five             super geeks constituting of technology lovers and computer science              enthusiasts have been constantly working in this direction.           

        
        
      
    
  
  

输出: