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

4th*_*ace 3 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: 'blue'});
});
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/bjf2L0ha/

dml*_*tle 7

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

$("#colorBtn").click(function() {
  $('#demodiv').animate({backgroundColor: 'blue'})
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<input type="button" id="colorBtn" value="Change Color"/><br>

<div id="demodiv" style="height:100px;width:100px;background:red"></div>
Run Code Online (Sandbox Code Playgroud)