基本上,我有一个透明的导航栏,该导航栏在滚动时变为白色,徽标从白色变为黑色。
这可以正常工作,但是我的问题是在一个特定页面上(/ toursearch)我的导航使用白色背景,并且只想显示黑色徽标。但是滚动类仍在应用,并导致我遇到问题。
所以我的问题是,除了巡回搜索页面之外,我如何定位其他所有页面?
HTML
<nav class="navbar navbar-expand-lg navbar-light bg-transparent">
<div class="container-fluid">
<button class="navbar-toggler collapsed nofocus" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="icon-bar top-bar"></span>
<span class="icon-bar middle-bar"></span>
<span class="icon-bar bottom-bar"></span>
</button>
<!-- LOGO -->
<div class="logo-desk d-none d-sm-none d-md-none d-lg-block">
<a class="navbar-brand" href="/"><img src="/Includes/images/logo/holts-logo-trans.png" class="img-fluid" /></a>
</div>
<!-- END LOGO -->
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item all-tours">
<a class="nav-link" href="/toursearch">Tours</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/destinations">Destinations<span class="mob-menu-icon float-right d-sm-block d-lg-none"><i class="fas fa-chevron-right"></i></span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="/about-us">About Us<span class="mob-menu-icon float-right d-sm-block d-lg-none"><i class="fas fa-chevron-right"></i></span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="/teaching-resources">Resources <span class="mob-menu-icon float-right d-sm-block d-lg-none"><i class="fas fa-chevron-right"></i></span></a>
</li>
</ul>
</div>
</div>
</nav>
jQuery
$(document).scroll(function () {
var $nav = $(".navbar-light");
$nav.toggleClass('scrolled', $(this).scrollTop() > $nav.height());
});
谢谢您的帮助。
答案 0 :(得分:0)
您可以在tour
页面的顶部指定一个特定的班级,例如
<body class='tourpage'>
然后相应地设置CSS:
.navbar-light .logo-desk { background-color: white; }
.tourpage .navbar-light .logo-desk { background-color: black }
.navbar-light.scrolled .logo-desk { background-color: black }
.tourpage .navbar-light.scrolled .logo-desk { background-color: white }
(更改css选择器/颜色以满足您的特定需求,如果没有当前的css很难说清楚,但是原理保持不变)。