Jquery Wait for animation to finish before leaving the function
<p>I have an animation inside a function. How can I code such that the animation should finish first before leaving the function?</p>

<p>Consider the code below:</p>

<pre><code>ShowBanner.prototype.basicRotate = function (pos, callback) {
    var self = this;
    self.animation = true;

    this.bigbannerScroll.animate({
        left: pos
    }, this.settings.rotateSpeed, function () {
        self.animation = false;
        if (callback) callback();
        console.log('animation done');
        return false;
    });

    console.log('function done');
}
</code></pre>

<p>Based on the code, the <code>console.log('function done')</code> is called first before the <code>console.log('animation done')</code>. Is there a way for the first log to be called first, stating that the animation was finished before leaving the function?</p>
