問題描述
我正在使用 Bootstrap 3,并希望在用戶滾動經過我的大標題圖像時實現 這種效果頁.我需要導航欄的背景從透明變為白色.我查看了他們的代碼,我知道它是用 javascript 完成的,甚至看到了 WHERE 我認為它發生了(在那個 JS 中查找 ID '#main-header')...
I'm using Bootstrap 3 and want to achieve this effect when the user scrolls past the large header image on my page. I need the background of the navbar to go from transparent to white. I looked in their code and I KNOW it is done with javascript, and even saw WHERE it was happening I think (look for the ID '#main-header' in that JS)...
除了不了解高級 Javascript 之外,我正在尋找一種在滾動超過某個點時將其應用于導航欄的方法.我的代碼的類稱為導航欄",我希望它在通過#main"時變成白色.如果您需要更多信息,請告訴我,如果有人想提供幫助,請提前致謝!
Not knowing advanced Javascript aside, I'm looking for a way to apply this to my navigation bar when scrolling past a certain point. The class for my code is called 'navbar' and I would like it to turn white when it passes "#main". Let me know if you need more information, and thanks in advance if anyone wants to help!
推薦答案
如果你使用 Twitter Bootstrap,這可以通過'Affix' 插件
If you're using Twitter Bootstrap this can be achieved with the 'Affix' plugin
設置起來非常簡單,這里是文檔
這篇關于滾動經過錨點時,如何使導航欄更改 CSS 類?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!