[英]Animating to another background-color, then back again
I'm trying to make my white background flash green. 我正试图让我的白色背景闪烁绿光。 Currently I have this code which turns it green:
目前我有这个代码,它变成绿色:
$( "#modal_newmessage" ).animate({
backgroundColor: "#8bed7e"
}, 500 );
However, I can't figure how to make it turn white again in the same animation. 但是,我无法想象如何让它在同一个动画中再次变白。 How do I do this?
我该怎么做呢?
You can chain another .animate()
call since the animations will be queued in the fx
queue. 您可以链接另一个
.animate()
调用,因为动画将在fx
队列中排队。
$("#modal_newmessage").animate({
backgroundColor: "#8bed7e"
}, 500).animate({
backgroundColor: "#fff"
}, 500);
Remember most jQuery functions are chainable without need to call $("#modal_newmessage")
twice. 请记住,大多数jQuery函数都是可链接的,无需两次调用
$("#modal_newmessage")
。
This should work: 这应该工作:
$( "#modal_newmessage" ).animate({
backgroundColor: "#8bed7e"
}, 500, function() {
$( "#modal_newmessage" ).animate({ backgroundColor: "#fff" });
} );
Try this: 试试这个:
$(function() {
$( "#modal_newmessage" ).animate({
backgroundColor: "#aa0000",
color: "#fff",
width: 500
}, 1000 ).animate({
backgroundColor: "#fff",
color: "#000",
width: 240
}, 1000 );
});
For animating background colors you need jQuery ui
for color animation. 对于动画背景颜色,您需要
jQuery ui
用于颜色动画。
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.