首先,我想解釋我想要做什麼,我想更改滾動時某個CSS樣式的值爲border-bottom-color
。但問題是,它不工作,而另一種風格正在工作.navbar-inverse .navbar-nav>li>a
。有人可以解釋爲什麼它不起作用嗎?我是HTML和CSS的新手。滾動時更改CSS樣式的值
$(document).ready(function() {
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll > 36) {
$(".navbar-inverse .navbar-nav>li>a").css("color", "white"); //Working
$(".navbar-inverse .navbar-nav>li>a:hover").css("border-bottom-color", "white");
} else {
$(".navbar-inverse .navbar-nav>li>a").css("color", "black"); //Working
$(".navbar-inverse .navbar-nav>li>a:hover").css("border-bottom-color", "rgb(2,1,131)");
}
})
})
.navbar-inverse .navbar-nav>li>a {
color: black;
padding-top: 80px;
padding-left: 30px;
font-weight: bold;
border-bottom: 3px solid transparent;
transition: border-bottom-color 0.5s ease-in-out;
-webkit-transition: border-bottom-color 0.5s ease-in-out;
}
.navbar-inverse .navbar-nav>li>a:hover {
color: rgb(2, 1, 131);
border-bottom-color: rgb(2, 1, 131);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav class="navbar navbar-inverse" data-spy="affix" data-offset-top="36">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="http://www.serbizcooperative.com/"><img src="img/logo.png" class="logo" width="400px"></a>
<img src="img/gear.png" class="gear" width="15px">
<img src="img/lightning.png" class="lightning" width="25px">
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Careers</a></li>
<li><a href="#">Clients</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">Team</a></li>
<li><a href="#">HR Express</a></li>
<li><a href="#">Activities</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</div>
</div>
</nav>
你不能使用:懸停的CSS屬性爲腳本選擇。 –