gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 07:09:22 24 4
gpt4 key购买 nike

我做错了什么,以下内容没有为背景颜色设置动画?

<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'});
});

http://jsfiddle.net/bjf2L0ha/

最佳答案

您需要导入额外的插件,例如 jQuery UI为了支持 animate() 函数中的颜色,而 jQuery 本身并不支持颜色。

$("#colorBtn").click(function() {
$('#demodiv').animate({backgroundColor: 'blue'})
});
<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>

关于jquery - 如何在 jQuery 中设置背景颜色动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31353418/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com