我有一個元素,我試圖用頁面滾動時使用jQuery動畫。我試圖讓元素的背景顏色從透明變爲黑色。我一直在嘗試不同的方法來完成這個問題,但他們都沒有工作。請幫忙。jQuery Wont動畫
$(window).scroll(function() {
if ($(window).scrollTop() >= 100) {
$("#heading").animate({
backgroundColor: "rgb(10,22,18,0)"
}, "slow");
} else {
$("#heading").animate({
backgroundColor: "rgb(10,22,18,1)"
}, "slow");
}
});
#heading {
z-index: 2;
position: fixed;
height: 30px;
border: none;
background-color: rgb(10, 22, 18, 0);
}
.head {
display: inline;
float: left;
opacity: 1.0;
}
.head2 {
height: 30px;
width: auto;
padding-left: 5px;
padding-right: 5px;
text-align: center;
text-shadow: 1px 1px 3px #666666;
color: rgb(255, 255, 255);
font-size: 15px;
text-decoration: none;
border: none;
background: none;
}
.head2:hover {
color: rgb(255, 255, 255);
text-decoration: none;
background-color: rgb(0, 0, 0);
}
.font {
font-family: 'Raleway', sans-serif;
font-style: normal;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="heading">
<img class="head" id="mainImg" src="Images/logo.png" alt="Know Music">
<button class="head head2 font" href="" id="hb1">Guitar</button>
<button class="head head2 font" href="" id="hb2">Bass</button>
<button class="head head2 font" href="" id="hb3">Piano</button>
<button class="head head2 font" href="" id="hb4">Drums</button>
</div>