How do I make my navbar change CSS class upon scrolling past an anchor point?(滚动经过锚点时,如何使导航栏更改 CSS 类?)
问题描述
我正在使用 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 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:滚动经过锚点时,如何使导航栏更改 CSS 类?


- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01