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

Add subnav component and behavior to BS core #1189

Closed
dbpolito opened this issue Jan 25, 2012 · 61 comments
Closed

Add subnav component and behavior to BS core #1189

dbpolito opened this issue Jan 25, 2012 · 61 comments
Milestone

Comments

@dbpolito
Copy link

I loved the way you did the subnav on docs, i would love that becomes an component and javascript plugin.

@dwightwatson
Copy link

+1

@Anahkiasen
Copy link

Thought the same thing when I realized that it wasn't incorporated in Bootstrap.

@alienlebarge
Copy link
Contributor

+1

@mdo
Copy link
Member

mdo commented Jan 25, 2012

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.

@wjrichardson
Copy link

+1

4 similar comments
@simonfranz
Copy link

+1

@sindresorhus
Copy link
Contributor

👍

@t1mmen
Copy link

t1mmen commented Jan 27, 2012

+1

@andriijas
Copy link
Contributor

+1

@anandanjaria
Copy link

I could replicate the subnav but dropdown is not working on it :(

@TuckerWhitehouse
Copy link

+1

1 similar comment
@thomasfedb
Copy link

+1

@mdo
Copy link
Member

mdo commented Jan 30, 2012

No need to keep +1ing, folks—we'll add it when we can :).

@quangbahoa
Copy link

+1

1 similar comment
@pierrebeitz
Copy link

+1

@darklow
Copy link

darklow commented Feb 4, 2012

already using subnav, stolen from docs.css :)
+1

@splaice
Copy link

splaice commented Feb 4, 2012

+1

9 similar comments
@PiotrKaczor
Copy link

👍

@KonstantinReido
Copy link

+1

@nnordrum
Copy link

nnordrum commented Feb 7, 2012

+1

@meshakeeb
Copy link

+1

@g00fy-
Copy link

g00fy- commented Feb 15, 2012

+1

@ADO
Copy link

ADO commented Feb 15, 2012

+1

@palpalani
Copy link

👍

@Tuckie
Copy link

Tuckie commented Feb 21, 2012

+1

@akennedy
Copy link

+1

@fat
Copy link
Member

fat commented Feb 25, 2012

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.

@winterstetter
Copy link

@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!

@gavinwye
Copy link

gavinwye commented Mar 8, 2012

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 <head> of your document like this. The file that I'm using the subnav in is in the root of my site hence the path.

<link href="../docs/assets/css/docs.css" rel="stylesheet">

Make sure the <body> looks like this

<body data-spy="scroll" data-target=".subnav" data-offset="50">

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.

<script src="/docs/assets/js/application.js"></script>

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.

@andriijas
Copy link
Contributor

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.

@vaughany
Copy link

+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. :)

@mdo
Copy link
Member

mdo commented Mar 25, 2012

Updating this issue a bit to clarify what we'll do for this component. Here's what I think we'll do:

  • add the styles for it as a standard, static component via HTML/CSS
  • abstract the javascript behavior to for fixing a component to the top as a separate plugin

We'll update with more info as we go. Thanks!

@slawosz
Copy link

slawosz commented Apr 12, 2012

👍

12 similar comments
@nisley
Copy link

nisley commented Apr 24, 2012

+1

@quorak
Copy link

quorak commented Apr 30, 2012

+1

@skython
Copy link

skython commented May 3, 2012

+1

@add1ct3dd
Copy link

+1

@eugenesaur
Copy link

+1

@mabuzer
Copy link

mabuzer commented May 13, 2012

+1

@richwestcoast
Copy link

👍

@inactivist
Copy link

👍

@testeria
Copy link

👍

@hirmes
Copy link

hirmes commented Jun 2, 2012

+1

@XavierColombel
Copy link

+1

@Sephen
Copy link

Sephen commented Jun 26, 2012

+1

@samuelclarke
Copy link

+1 :)

@ziegenberg
Copy link

yay, it's there! one closed.

@richwestcoast
Copy link

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
------Original Message------
From: Daniel Ziegenberg
To: Richard Winder
Subject: Re: [bootstrap] Add subnav component and behavior to BS core (#1189)
Sent: 28 Jun 2012 00:23

yay, it's there! one closed.


Reply to this email directly or view it on GitHub:
#1189 (comment)

Sent from my BlackBerry® wireless device

@inactivist
Copy link

On 6/27/2012 4:24 PM, Richard wrote:

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

Because it's tagged as 'open'...?

@samuelclarke
Copy link

Why +1 it? Just to show support for a feature that I think many people, including me, would find very useful. :)

@richardp-au
Copy link

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.

@samuelclarke
Copy link

Pardon me missing that...I'm newer to GitHub and overlooked that. Still, even so another +1 for the 2.1.0 milestone! ;)

@miki725
Copy link

miki725 commented Jul 2, 2012

+1

@ziegenberg
Copy link

Shouldn't someone close this ticket as it's closed for the next version?

+1

@bguiz
Copy link

bguiz commented Jul 6, 2012

+1

1 similar comment
@hnordt
Copy link

hnordt commented Jul 9, 2012

+1

@mdo
Copy link
Member

mdo commented Jul 10, 2012

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.

@mdo mdo closed this as completed Jul 10, 2012
@twbs twbs locked and limited conversation to collaborators Jun 9, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests