gpt4 book ai didi

jquery - 使用 jquery animate 更改背景颜色

转载 作者:行者123 更新时间:2023-12-01 06:12:59 32 4
gpt4 key购买 nike

我有以下 html 代码:`

<html> 
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("div").animate({
backgroundColor: '#f5f5f5',
});
});
});
</script>
</head>

<body>
<button>Start Animation</button>
<p>By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!</p>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>

</body>
</html>`

但是我无法使用 animate 来更改背景颜色。
请让我知道出了什么问题?

谢谢
史密斯哈

最佳答案

为了支持背景颜色更改,您需要包含 jQuery UI 或 jQuery 颜色库

From Docs

For example, width, height, or left can be animated but background-color cannot be, unless the jQuery.Color() plugin is used

$(document).ready(function () {
$("button").click(function () {
$("div").animate({
backgroundColor: 'red',
});
});
});

演示:jQuery UI
演示:jQuery Color

所以添加

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/color/jquery.color-2.1.2.js"></script>

关于jquery - 使用 jquery animate 更改背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20540807/

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