Twitter Bootstrap scrollspy总是选择最后一个元素 [英] Twitter Bootstrap scrollspy always selecting last element

查看:249
本文介绍了Twitter Bootstrap 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'数据'标签,所以我打电话给 scrollspy()通过JavaScript激活插件。

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.

下一步是删除固定内容高度并使用词缀

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总是选择最后一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆