question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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.

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:18 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
bluepinescommented, May 2, 2012

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);
});
1reaction
gbertbcommented, May 16, 2012

@bluepines’ code works great, thanks!

var offset = 80;

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

github_iconTop Results From Across the Web

bootstrap scrollspy bug when resizing browser - Stack Overflow
Use the navbar. (notice that the url has changed to include #section ) this only occurs if you resize the browser. This causes...
Read more >
Bug: Vanilla Bootstrap Scrollspy not working after including
scrollspy ({ target: '#main-navbar', offset: 50 }) }); I tied it not even working by javascipt instead of data api. The movement I...
Read more >
Scrollspy activates links erratically - Bootstrap Studio Forum
It seems like Scrollspy activates the links in a very erratic manner. ... Scrollspy activates links erratically · Bug Reports.
Read more >
CSCvq93771 - Bootstrap scrollspy Data-Target ... - Cisco Bug
Bug information is viewable for customers and partners who have a service contract. Registered users can view up to 200 bugs per month ......
Read more >
Scrollspy nav BUG - YOOtheme Support
Scrollspy nav BUG. hi,. uikit documentation. yootheme pro documentation. I found out that Scrollspy nav (https://getuikit.com/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found