問題描述
我對在這個小提琴中重新創建的 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 總是選擇最后一個元素的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!