Twitter Bootstrap affix events not firing
Asked Answered
P

3

10

I'm trying to affix a toolbar when the user scrolls passed it. The affix portion works fine however I want to adjust the padding on my main container when the affix class actually get applied. http://getbootstrap.com/javascript/#affix-usage Has some events listed However; I can't get any of them to fire. The JSfiddle doesn't look right I'm guessing cuz of the size. But essentially none of those events get fired when the affix is applied to the #nav.

$('#nav').on('affix.bs.affix', function () {
     alert('Fired!');
});

You can see more of my code here.. Its essentially just the navbar given in the BS example.

http://jsfiddle.net/dTR4A/1/

Peddada answered 3/2, 2014 at 17:26 Comment(0)
F
8

The affix.bs.affix event fires when the affixed element is scrolled so if you scroll the page:

This event fires immediately before the element has been affixed.

so make your page content higher.

Demo: http://jsfiddle.net/4vmMd/

Fealty answered 3/2, 2014 at 18:34 Comment(3)
I couldn't for the life of me get your example to work. It had something to do with my bootstrap.min.js .. I used the version JSFiddle was using and it worked. Thanks +1Peddada
Same problem here, there must be a bug with the earlier versions of bootstrap 3.Buber
Had the same issue too, updating 3.0.2 to 3.1.1 did the trick for me.Pasol
V
1

Encountered a similar problem.. Turns out that it was older version of bootstrap. It worked just fine with newer version. Also ensure that your content has enough height.

Vansickle answered 12/9, 2015 at 9:28 Comment(0)
M
0

For future travelers falling into this issue, I was having the same issue but the above solutions did not work for me.

I found out that in a completely remote part of my application, we have:

$(window).unbind('scroll')
$(window).off('scroll')

Which was killing the handler for the scroll event (probably, the Affix library observes the $(window) element in order to fire the scrolling events).

Hope this helps.

Malloy answered 26/9, 2016 at 11:43 Comment(1)
and how did you bind it again that the affix know the handlerConcealment

© 2022 - 2024 — McMap. All rights reserved.