twitter-bootstrap Twitter Bootstrap 词缀事件未触发
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21533658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Twitter Bootstrap affix events not firing
提问by Christopher Jazinski
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-usageHas 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.
当用户滚动通过它时,我试图贴上工具栏。词缀部分工作正常,但是我想在实际应用词缀类时调整主容器上的填充。http://getbootstrap.com/javascript/#affix-usage列出了一些事件但是;我不能让他们中的任何一个开火。JSfiddle 看起来不正确,我猜是因为大小。但基本上当词缀应用于#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.
你可以在这里看到更多我的代码..它本质上只是BS示例中给出的导航栏。
采纳答案by Irvin Dominin
The affix.bs.affixevent fires when the affixed element is scrolled so if you scroll the page:
affix.bs.affix滚动附加元素时会触发该事件,因此如果滚动页面:
This event fires immediately before the element has been affixed.
此事件在元素被附加之前立即触发。
so make your page content higher.
所以让你的页面内容更高。
回答by Chromonav
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.
遇到了类似的问题..原来是老版本的bootstrap。它适用于较新的版本。还要确保您的内容具有足够的高度。
回答by iorrah
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 handlerfor the scroll event (probably, the Affixlibrary observes the $(window)element in order to fire the scrolling events).
这是杀死handler滚动事件的(可能,词缀库观察$(window)元素以触发滚动事件)。
Hope this helps.
希望这可以帮助。

