JAVASCRIPT SOLUTION
Well, there are two possibilities for you to try to speed it up.
First of all, when you change the style of an element, you force the browser to reset the page. This is called repainting. Some changes also lead to recalculation of page geometry. This is called reflow. Re-melting always causes a redraw immediately after it. I think, why you experience worse performance with a lot of elements, is that each update of each of them causes at least redrawing. What is usually recommended when modifying several styles in one element is to either do them all at once, adding or removing a class, or hiding an element, do your manipulations and then show it, which means only two copies (for example , and, possibly, recounts).
It seems that in this particular case, you are probably already doing a great job, as you process each element only once per iteration.
Secondly, requestAnimationFrame () is good for creating animations on a canvas element, but it seems to have some tricky performance for DOM elements. Open your page in the Chrome profiler to see exactly where it freezes. Try just using setTimeout () to make sure it is. Again, the profiler will tell you where the hangs are. requestAnimationFrame () should be better, but confirm it. I used to have unpleasant consequences.
REAL SOLUTION
Do not do this in JavaScript, if you can avoid it at all. Use CSS transitions and translation to animate using a JavaScript function registered as an onTransitionEnd event handler for each animated element. Providing the browser with this material is almost always faster from the start than any JS code anyone can write.
The only catch is that CSS3 animations are only supported by new browsers. For your own edification, do it like this. For real practical applications, delegate to the library. A good library will do this initially, if possible, and will return to a better way to do this in JS for older browsers.
A good read link regarding this material: http://www.html5rocks.com/en/tutorials/speed/html5/