如何在jQuery中设置背景色动画?

如何在jQuery中设置背景色动画?,jquery,Jquery,我做错了什么,下面没有动画背景颜色 <div style="height:100px;width:100px;background:red">animate this</div><br> <input type="button" id="mybutton" value="start"/><br> $("#mybutton").click(function(){ $("div").animate({backgroundColor

我做错了什么,下面没有动画背景颜色

<div style="height:100px;width:100px;background:red">animate this</div><br>
<input type="button" id="mybutton" value="start"/><br>


$("#mybutton").click(function(){
   $("div").animate({backgroundColor: 'blue'});
});
制作动画

$(“#我的按钮”)。单击(函数(){ $(“div”).animate({backgroundColor:'blue'}); });

您需要导入一个额外的插件,例如,以支持
animate()
函数中的颜色,因为jQuery本身不支持

$(“#colorBtn”)。单击(函数(){
$('#demoiv')。动画({backgroundColor:'blue'})
});



尝试在
.animate()的
步骤
选项中为
css
背景色
属性设置
rgb

var props={
起:255,
致:0
},
div=$(“div”),
按钮=$(“#我的按钮”);
按钮。单击(函数(){
$(道具).finish().animate({
//在“蓝色”、“红色”之间切换
from:props.from==255?0:255,
to:props.to==0?255:0
}, {
放松:“线性”,
时长:3000,
步骤:函数(){
div.css(“背景色”
,“rgb(”
+数学圆(这个从)
+ ", 0, " 
+数学四舍五入(此为“+”);
}
});
});

制作动画