Twitter Bootstrap scrollspy always selecting last element(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();
这篇关于Twitter Bootstrap scrollspy 总是选择最后一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Twitter Bootstrap scrollspy 总是选择最后一个元素


基础教程推荐
- npm start 错误与 create-react-app 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01