bootstrap: scrollspy bugs

hey, i am having a ton of issues getting scrollspy to work properly.

Issue 1:

$('.navbar').scrollspy({offest: 70});

Changing the offest and then clicking on the links does nothing. It refuses to acknowledge the offest when you click the links although it does respect the offset when you are scrolling down the page.

Issue 2:

 $('.navbar li').on('activate', function(){console.log('activate')});

This callback does not get called because of this line, which I’m guessing always evaluates to true.

 if ( active.parent('.dropdown-menu') )  {
      active = active.closest('li.dropdown').addClass('active')
 }

Also, I am getting weird behavior where one of the last nav element is auto selected.

About this issue

  • Original URL
  • State: closed
  • Created 12 years ago
  • Comments: 18 (1 by maintainers)

Commits related to this issue

Most upvoted comments

So this is how I got it to finally go to the proper place when you click on the navigation. I added an event handler for the navigation clicks. Then you can just use “scrollBy” to move up on the offset.

var offset = 80;

$('.navbar li a').click(function(event) {
    event.preventDefault();
    $($(this).attr('href'))[0].scrollIntoView();
    scrollBy(0, -offset);
});

@bluepines’ code works great, thanks!

var offset = 80;

$('.navbar li a').click(function(event) {
    event.preventDefault();
    $($(this).attr('href'))[0].scrollIntoView();
    scrollBy(0, -offset);
});