Twitter Bootstrap scrollspy 总是选择最后一个元素

我对在这个小提琴中重新创建的 scrollspy 有疑问:http://jsfiddle.net/jNXvG/3/

I have an issue with scrollspy, recreated in this fiddle: http://jsfiddle.net/jNXvG/3/

正如演示中所见,无论滚动位置如何,ScrollSpy 插件始终保持最后一个菜单项被选中.我已经阅读了其他问题和答案,并尝试了 offset 等的不同组合,但没有一个有帮助.我不知道出了什么问题.

As seen in the demo, the ScrollSpy plugin always keeps the last menu item selected no matter the scrolling position. I've read other questions and answers and tried different combinations of offset, etc., but none of them have helped. I can't figure out what's wrong.

我不想编辑我的模板来包含丑陋的 html 'data' 标签,所以我通过 JavaScript 调用 scrollspy() 来激活插件.

I don't want to edit my template to include ugly html 'data' tags, so I am calling scrollspy() via JavaScript to activate the plugin.

下一步是移除固定的内容高度并在侧边栏使用 'affix'.

The next step would be to remove the fixed content height and use 'affix' on the sidebar.

推荐答案

您需要将 ScrollSpy 附加到将要触发滚动事件的元素,而不是要反映滚动位置的菜单:

You need to attach the ScrollSpy to the element that is going to trigger scroll events, rather than the menu that is going to reflect the scroll position:

$('#content').scrollspy();​

相关文章