gpt4 book ai didi

javascript - jQuery 使用淡入淡出更改背景颜色并延迟返回原始颜色

转载 作者:行者123 更新时间:2023-11-28 08:28:52 34 4
gpt4 key购买 nike

我有以下功能,应该用淡入淡出改变背景颜色,然后使用延迟返回到原来的颜色。并无休止地重复。

$(function () {
$('div').animate({background-color: 'blue'}, 'slow', function () {
$(this).delay(500).animate({background-color: 'red'}, 'slow');
});
});

不过好像不行。。。任何想法如何解决它?

最佳答案

请不要忘记包含 jquery-ui 库。否则它不起作用

$(document).ready(function() {

$('.sample').click(function() {

$(this).animate({
backgroundColor: "green"
}, 1000).delay(2000).queue(function() {
$(this).animate({
backgroundColor: "red"
}, 1000).dequeue();
});

});

});
.sample {
font: normal 12px/18px 'Arial';
color: #fff;
background: red;
padding: 20px;
cursor: pointer
}
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<div class="sample">
Click Me to see smooth background color transition and back to original background
</div>
</body>

关于javascript - jQuery 使用淡入淡出更改背景颜色并延迟返回原始颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28389322/

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