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?
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?
Share Improve this question asked Jan 22, 2013 at 17:32 Patrick ReckPatrick Reck 11.4k11 gold badges56 silver badges88 bronze badges3 Answers
Reset to default 4You can chain another .animate()
call since the animations will be queued in the fx
queue.
$("#modal_newmessage").animate({
backgroundColor: "#8bed7e"
}, 500).animate({
backgroundColor: "#fff"
}, 500);
Remember most jQuery functions are chainable without need to call $("#modal_newmessage")
twice.
See it here.
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 );
});
note:
For animating background colors you need jQuery ui
for color animation.
<script src="http://code.jquery./jquery-1.8.3.js"></script>
<script src="http://code.jquery./ui/1.10.0/jquery-ui.js"></script>