This post is kinda drafty, but since the Google’s first page for this were outdated, here we go!
When trying running 2 animations (or multiple) side by side (in parallel) at a same element, via JQuery .animate() they run one after another; like they are supposed to do by default, but there is a argument to override; queue. In a silly example:
j('body').animate({ paddingTop: 100}, 500, function(){ alert('Took half a second!')}).animate({paddingLeft: 100}, {duration: 500, queue:false})
Here we are animating both in parallel, and the callback alert, run after half a second. (*be careful about callbacks on animations with queue:false, since they don’t seem to trigger )
In another example, fairly more complex (and real
), I am using JQueryUI for both shake, and color effects.
The objective is to simulate a div that gets overheated and waves to chill, real fast.
var pointsE = j('#health_bar .stats')
pointsE.css( {color: 'rgb(255,0,0)' })
.stop(true)
.effect('bounce', {times: 5, distance:10, easing: 'easeOutElastic'}, 300 )
.html('OUCH!')
.animate({ color: 'rgb(255,255,255)' }, { duration: 500, queue: false})
Just be aware, that it doesn’t seen .effect(), supporting queue: false –it breaks. That’s why I put it in the .animate()
About the .stop(true), it is just to be sure that the queue is empty before starting the animation (in practice, it is a minor fix for consecutive .effect(‘shake’))
References:
jQuery .animate() API
jQueryUI Color
jQueryUi Shake Effect

