jqueryjquery-animateshake

jQuery effect() and animate() methods at the same time


I need to shake div and animate its background-color color at the same time.

Here is the JSFiddle example: http://jsfiddle.net/EUz4z/

$("#test").effect("shake", {}, 500 ).css("background-color","red").animate({backgroundColor: old_bg}, 500 );
})

Solution

  • You can use the queue: false option:

    http://jsfiddle.net/ysFcD/

    $(document).ready(function(){
        $("#but").click(function(){
            old_bg=$("#test").css("background-color");
            $("#test").effect("shake", {  }, 500 )
                .css("background-color","red")
                .animate({backgroundColor: old_bg}, {duration: 500, queue: false } );
        })
    });