Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

activate.bs.scrollspy not being called with a dropdown? #11477

Closed
matchew opened this issue Nov 13, 2013 · 4 comments
Closed

activate.bs.scrollspy not being called with a dropdown? #11477

matchew opened this issue Nov 13, 2013 · 4 comments
Labels
Milestone

Comments

@matchew
Copy link

matchew commented Nov 13, 2013

I have this Table of Contents in a dropdown and I want to use scrollspy() to keep track of where I am in the document. I often have hundreds of pages so a dropdown with and `overflow-y: auto;`` makes some design sense at this point. However, I also would like to do some other things when the page changes. Notably Change Page # on the dropdown button to the actual page. According to the documentation I would use something like the following:

$('#myScrollspy').on('activate.bs.scrollspy', function () {
  // do something…
});

however, this fails to work. see the following fiddle: http://jsfiddle.net/2W8AC/

@fat fat closed this as completed in 7545da2 Nov 15, 2013
@fat
Copy link
Member

fat commented Nov 15, 2013

oh ya, that's my bad – in the short term just use .on('activate'), but going forward you'll need the bs.scrollspy

@matchew
Copy link
Author

matchew commented Nov 15, 2013

Thanks for taking a look, I meant to update this the other day. Because my solution was different.

Funny you notice the trigger('activate') in the js. Because that is exactly what I saw first when digging in the source. But, just using .on('activate') does not work. (see: http://jsfiddle.net/2W8AC/1/), in fact, you can get.on(activate.bs.scrollspy)` working using the demo markup from the docs => http://jsfiddle.net/qw36f/

It turned out my problem was related to my markup. If you notice at line 110 in scrollspy.js or about 1699 in dist the following portion:

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

I was missing <li class="dropdown">. once the class was added everything seemed to work just fine.
see => http://jsfiddle.net/Mt25g/2/

there was some discussion about this as well in IRC too.

@mdo mdo mentioned this issue Nov 16, 2013
@fredrikhirsch
Copy link

Would it be possible to get the dropdown menu to show which section currently being viewed? For example, when the section "Sauges" is focused the dropdown menu itself should indicate this.

@cvrebert
Copy link
Collaborator

@fredrikhirsch Yes, although you do need to use a Nav component (but not necessarily a Navbar); the Scrollspy example in the docs demonstrates this: http://getbootstrap.com/javascript/#scrollspy-examples

@twbs twbs locked and limited conversation to collaborators May 23, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants