html - 需要在滚动时更改背景颜色
问题描述
在我们的网站中,我试图更改滚动标题的背景颜色,但我没有得到任何特定于该滚动操作的 id 或类。
请在以下网址找到:http: //indemortgage.staging.wpengine.com/
请用解决方案回复我
已经尝试过以下代码:
$(function() {
$(window).on("scroll", function() {
if($(window).scrollTop() > 50) {
$(".header").addClass("active");
} else {
//remove the background property so it comes transparent again (defined in your css)
$(".header").removeClass("active");
}
});
});
我希望相关的 id 或类在滚动时更改背景颜色。
解决方案
在您的网站标题中没有类。那么你可以在jquery中删除(点)并添加标题吗
$(function() {
$(window).on("scroll", function() {
if($(window).scrollTop() > 50) {
$("header").addClass("active");
} else {
//remove the background property so it comes transparent again (defined in your css)
$("header").removeClass("active");
}
});
});
css
header.active{
background-color:red;
}
推荐阅读
- java - 对话框中的 EditText.setText("") 使应用程序崩溃
- jquery - Select2 从过滤列表中选择所有选项以进行多项选择
- java - JTable CellRenderer 仅在聚焦时更改前景色
- node.js - 如何在使用 Outlook api 创建日历事件时隐藏来宾列表/与会者以查看其他与会者
- symfony - 如何覆盖“公共”目录?
- javascript - 数据推入数组会覆盖值
- node.js - Vue|Nuxt - 将项目复制到生产服务器导致错误
- reactjs - 如何将边框底部放在reactjs中的react-chips?
- c# - 如何获得 Hyper-V VM 来宾操作系统
- ruby-on-rails - 如何访问哈希中的嵌套键