Reputation: 119
Read the github documentation, bug is well know and it was suppose to have been fixed in 2.1.. but it hasn't?
Essentially... you can offset the data the scrollspy uses HOWEVER that offset does NOT affect the actual clicking of the tab.
Any help on finding a solution?
This is the site I am trying to fix: www.powerliftingbasics.com
Upvotes: 2
Views: 683
Reputation: 76980
As per @fat's comment on Issue #3316: Scrollspy Bugs:
$('.navbar').scrollspy({offest: 70});
is only intended to modify scrolling calculations - we don't shift the actual anchor click stuff, that's on you. The plugin is only for spying on scrolls.
That is, ScrollSpy just observes, it doesn't control browser scroll.
The Twitter Bootstrap page solves it by using a padding-top: 30px
on the sections that are linked to. Otherwise you could deal with it with JS:
function adjustScrollForNavbar() {
var $nav = $('div.navbar')
if ( $nav.css('position') !== "fixed" ) return
window.scrollBy(0, -$nav.height())
}
// Adjust for fixed navbar
$('body').on('click.scroll-adjust', '[href^="#"]', function (e) {
if ( e && e.isDefaultPrevented() ) return
$(window).one('scroll', adjustScrollForNavbar )
});
Obviously the CSS fix would be preferable.
Upvotes: 2