繁体   English   中英

更改滚动 JQuery 上活动菜单的颜色

[英]Change color of active menu on Scroll JQuery

我正在使用脚本来更改滚动导航链接的颜色,但我不知道如何为活动链接执行此操作,有人可以帮忙吗?

<script>
jQuery(document).ready(function(){
jQuery(window).scroll(function() {
var scroll = jQuery(window).scrollTop();

if (scroll >= 100) {
jQuery(".current-menu-item").addClass("current-menu-item-sticky");
}
else{
jQuery(".current-menu-item").removeClass("current-menu-item-sticky");
}
});
});
</script>

这个 class 代码负责颜色,如何更新滚动颜色?

.et_pb_menu_0_tb_header.et_pb_menu ul li.current-menu-item a {
    color: #fff!important;
}

由于您没有提供标记,您仍然可以通过使 css 选择器更宽来解决此问题,在滚动中添加的 class current-menu-item-sticky甚至不存在于您的 ZC7A628CBA22E228EB17B5F5C66AZ 中。

所以开始使用这个 css

.current-menu-item-sticky {
   color:#fff!important;
}

如果这没有改变任何东西,原因对我来说很清楚,所有其他颜色 css 不应该有。重要或有正确的顺序,所以正确的 !important 将被应用。

您可以轻松使用浏览器的元素检查器并查看应用了哪些 css 以及覆盖了哪些 css

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM