Bootstrap scrollspy only gets height offset on second click

前端 未结 1 2004
面向向阳花
面向向阳花 2021-01-24 11:23

I\'ve made a page with bootstrap 3.2.1 and use scrollspy in this page. In the first click on menu doesn\'t work offset height for scroll page, But after the second click works o

1条回答
  •  借酒劲吻你
    2021-01-24 11:43

    That because you set the navbar to fixed on scroll down (after y > 90). So you need to discount the height of the navbar when it's fixed.

    You need a dynamic value, based on your code, a way to do this is using a function with the same parameters. The height of the navbar is 30px so you need to add it.

    function offsetHeight() {
      if ($(window).scrollTop() > 90) {
        return 120;
      }
      else {
        return 150;
      }
    }; 
    

    JSFiddle

    0 讨论(0)
提交回复
热议问题