html - 需要更改滚动条的背景颜色

标签 html css wordpress

在我们的网站上,我试图更改滚动时标题的背景颜色,但我没有获得任何特定于该滚动操作的 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 或类在滚动时更改背景颜色。

最佳答案

我已经检查了您的可共享链接并观察到页面滚动上已经将一个类添加到标题和滚动顶部,它也被删除。 “header--not-sticked”这个类在它没有滚动时被添加到你的标题中,“header--is-sticked”这个类被添加到你的标题页面上是滚动的。因此,您可以使用这两个类轻松应用您的 CSS,希望这对您有所帮助。

Also, you have used the wrong class name to add and remove class, you need to remove "." from the header and make it an element because on your website there is no "header" class to your header element. Try the below code


$(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");
        }
    });
});

关于html - 需要更改滚动条的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58708504/

相关文章:

html - 等高列的边距不起作用

html - 未初始化的 WebGL Canvas 的替代方案

html - Firefox 中使用 Bootstrap 的负边距

jquery - 停止向上滑动 DC jQuery 垂直 Accordion 菜单上的当前元素

html - 在 div 下有很多空白区域?

html - 图像覆盖过多后,行高会影响文本与图像负边距对齐

php - WordPress 导航中某些 <li> 中的图像

javascript - 我可以在不使用 'this' 的情况下重写 Javascript 吗?

php - MYSQL 检索特色图片和帖子标题

html - 如何从具有 `display: table` 的 div 设置表头以坚持到顶部