jQuery Animate not working on background-color property

后端 未结 5 1846
迷失自我
迷失自我 2020-12-21 09:29

I was playing around with the jQuery .animate() function, and ended up trying to change the background-color of one of the divs depend

5条回答
  •  不知归路
    2020-12-21 10:10

    You can also animate the background color with jQuery, just not with the animate() method, as you have noticed, the css method will do.

    Since this is a very easy thing, do not include another library to the code, spare yourself the http requests and just do it with plain JS.

    This function will do just fine:

    function changeBG(el,clr){
    var elem = document.getElementById(el);
    elem.style.transition = "background 1.0s linear 0s";
    elem.style.background = clr;
    }
    

    Link to working example

    http://codepen.io/damianocel/pen/wMKowa

提交回复
热议问题