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
Add subnav component and behavior to BS core #1189
Comments
+1 |
Thought the same thing when I realized that it wasn't incorporated in Bootstrap. |
+1 |
Our subnav in the docs is a bit of a hack right now and for us to add to the repo would require a bit of reworking to make it the best it can be. We'll revisit after we push out 2.0 for a 2.x release. |
+1 |
4 similar comments
+1 |
👍 |
+1 |
+1 |
I could replicate the subnav but dropdown is not working on it :( |
+1 |
1 similar comment
+1 |
No need to keep +1ing, folks—we'll add it when we can :). |
+1 |
1 similar comment
+1 |
already using subnav, stolen from docs.css :) |
+1 |
9 similar comments
👍 |
+1 |
+1 |
+1 |
+1 |
+1 |
👍 |
+1 |
+1 |
If you're wondering how it's done - this is the js: // fix sub nav on scroll
var $win = $(window)
, $nav = $('.subnav')
, navTop = $('.subnav').length && $('.subnav').offset().top - 40
, isFixed = 0
processScroll()
$win.on('scroll', processScroll)
function processScroll() {
var i, scrollTop = $win.scrollTop()
if (scrollTop >= navTop && !isFixed) {
isFixed = 1
$nav.addClass('subnav-fixed')
} else if (scrollTop <= navTop && isFixed) {
isFixed = 0
$nav.removeClass('subnav-fixed')
}
} Maybe we add this to scrollspy? i'm not quite sure yet. |
@fat What's the trick to get the javascript to work? How exactly does it need to get inserted to make the scroll-wonder happen? Thanks! |
I just spent an hour figuring this out so here's how I did it. Please chip in if I'm doing something that is not necessary. Make sure that the link to the docs.css file is in the
Make sure the
data-spy is for scrollspy but I leave it in as it's sweet. You will also need the following at the end of the document, but providing you are using one on the bootstrap templates you should be fine.
And that's it. It should work. The only problem with this approach is you get the squared background image and your logo moves to the right in the navbar but you can just comment that out in docs.css Hope that helps. |
An hour? I dont want to rain on your parade but I just shipped in the code @fat pasted above together with the .subnav css of docs.css into my project and got a working subnav working in less than 5 minutes yesterday. Keep in mind .subnav needs to exist in the DOM when you bind the processScroll. If you inject a subnav with ajax just wrap the code in a function: var subnavfu = function(s) {
// fix sub nav on scroll
var $win = $(window)
, $nav = $(s)
, navTop = $(s).length && $(s).offset().top - 40
, isFixed = 0
processScroll()
$win.on('scroll', processScroll)
function processScroll() {
var i, scrollTop = $win.scrollTop()
if (scrollTop >= navTop && !isFixed) {
isFixed = 1
$nav.addClass('subnav-fixed')
} else if (scrollTop <= navTop && isFixed) {
isFixed = 0
$nav.removeClass('subnav-fixed')
}
}
}; you could use $('.subnav') instead of nav in processScroll but that would suck performence wise so dont do that. |
+1! It looks great and from a UI perspective it's really very useful. I managed to find the requisite js and css files and add them in, as well as the extra code in the tag, but the bar jumps to the right when it fixes, but hey, baby steps. :) |
Updating this issue a bit to clarify what we'll do for this component. Here's what I think we'll do:
We'll update with more info as we go. Thanks! |
👍 |
12 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
👍 |
👍 |
👍 |
+1 |
+1 |
+1 |
+1 :) |
yay, it's there! one closed. |
Ye not sure why peeps were +1ing the topic, its been there for a while.. Trying to be part of the cool kid crowd? :P yay, it's there! one closed. Reply to this email directly or view it on GitHub: Sent from my BlackBerry® wireless device |
On 6/27/2012 4:24 PM, Richard wrote:
Because it's tagged as 'open'...? |
Why +1 it? Just to show support for a feature that I think many people, including me, would find very useful. :) |
But it's had a milestone set for ages. Surely, there's no need to keep spamming the issue with +1s once it's got a milestone set. |
Pardon me missing that...I'm newer to GitHub and overlooked that. Still, even so another +1 for the 2.1.0 milestone! ;) |
+1 |
Shouldn't someone close this ticket as it's closed for the next version?
|
+1 |
1 similar comment
+1 |
The element itself has been added in 2.1.0-wip, but the javascript is not yet there. Since the affix plugin will drop with 2.1, we'll close this out. |
I loved the way you did the subnav on docs, i would love that becomes an component and javascript plugin.
The text was updated successfully, but these errors were encountered: