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 类?


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