scroll - 唤醒时在滚动时更改引导导航栏图像
问题描述
我被卡住了,我不知道如何在滚动过程中更改图像源(白色徽标到黑色徽标)。这是我正在处理的页面的链接: https ://www.camarilloflightinstruction.com/sandbox/2020/index.html
如果您滚动页面,您会注意到徽标将字体格式从 WHITE FRONT W/ DARK Background 更改为 BLACK FONT W/ White Background
有人可以指出我正确的方向吗?
解决方案
您可以创建一个 jquery.scroll()
事件来测试scrollTop()
窗口的值(检查页面是否在顶部附近滚动),然后src
根据该值更改图像的属性。.scrollTop()
向下滚动时,窗口的值将增加。
尝试将其添加到元素的最后<body>
,在其他<script>
元素之后:
<script>
var base = 'https://www.camarilloflightinstruction.com/sandbox/2020/images/';
$(window).scroll(function(){
if($(this).scrollTop() > 100){
$('nav.navbar .navbar-brand img').attr('src', base + 'CFI_black.png')
}
else {
$('nav.navbar .navbar-brand img').attr('src', base + 'CFI_white.png')
}
})
</script>
推荐阅读
- java - 希望使用函数式编程来解决重复代码
- python - 使用 ReportLab 将页码和总页数正确添加到 PDF
- python - Python 3.6 不会以正确的编码方法转换用户输入
- xml - XML - 使用 XSD 验证属性
- javascript - 如何在 laravel 中获取带有星星的用户评分
- nginx - 使用 DNS 设置 Rancher + Kubernetes 的最佳方法是什么
- c# - Windsor IoC 命名注入:构造函数
- javascript - Javascript:一些访问者在访问页面后被重定向
- apache-spark - 使用 Spark 写入外部 Hadoop
- ios - 列表属性文本中的第二行未对齐