javascript - jQuery Wont Animate -


i have element trying animate using jquery when page scrolled. im trying have element's background color change transparent black color. ive been trying different methods accomplish problem, none of them have worked. please help.

$(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>

i added condition js add class once greater 100 , remove class when below that. tried toggleclass, flickering. added .change class on css background color change , added transition #heading id. jsfiddle backgroundcolor cannot animated using animate function within jquery unless use plugin. see jquery animate docs

$(window).scroll(function() {    if ($(window).scrolltop() >= 100) {      $("#heading").addclass(" change");    } else{    $("#heading").removeclass(" change");    }  });
html,body{height:3000px;}  #heading {    z-index: 2;    position: fixed;    height: 30px;    border: none;    background-color: rgb(10, 22, 18, 0);    transition: 0.5s ease-in-out all;  }    .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;  }      .change{    background-color: rgba(10,22,18,1);  }
<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="https://placehold.it/50x50" 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>


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -