最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Animating to another background-color, then back again - Stack Overflow

programmeradmin5浏览0评论

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 badges
Add a ment  | 

3 Answers 3

Reset to default 4

You 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>
发布评论

评论列表(0)

  1. 暂无评论