11

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/

4

3 回答 3

8

affix.bs.affix事件在附加元素滚动时触发,因此如果您滚动页面:

此事件在元素被附加之前立即触发。

所以让你的页面内容更高。

演示:http: //jsfiddle.net/4vmMd/

于 2014-02-03T18:34:37.763 回答
1

遇到了类似的问题。。原来是老版本的bootstrap。它适用于较新的版本。还要确保您的内容有足够的高度。

于 2015-09-12T09:28:52.830 回答
0

对于遇到此问题的未来旅行者,我遇到了同样的问题,但上述解决方案对我不起作用。

我发现在我的应用程序的一个完全远程的部分,我们有:

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

这正在杀死handler滚动事件(可能,Affix库观察$(window)元素以触发滚动事件)。

希望这可以帮助。

于 2016-09-26T11:43:01.510 回答