jQuery animate({top: x}) very laggy in everything but chrome
<p>I've been trying to write a very simple animated sticky side bar using jQuery and its animate() function to change the top: CSS property of a div. Unfortunately in everything but chrome, it can get very laggy. I'm assuming its filling the memory every time the window scrolls and it calculates a newTop. Is there a better way to do this?</p>

<pre><code>$(function() { // document ready 
    var $sticky = $('.sticky');
    var stickyTop = $sticky.offset().top;
    var padding = 0;
    var stickyMargin = parseInt($sticky.css('margin-top')) + padding;
    var intersection = stickyTop - stickyMargin;

    $(window).scroll(function(){
        var windowTop = $(window).scrollTop();

        if (intersection &lt; windowTop) {
            var newTop = (windowTop - intersection);
            $sticky.stop().animate({top: newTop}, 'slow');
        }
        else if ($sticky.offset().top != 0) {
            $sticky.stop().animate({top: 0}, 'slow');
        }
    });
});
</code></pre>
