Hi all,
An interesting read over at mozHacks:
http://hacks.mozilla.org/2010/08/more-efficient-javascript-animations-with-mozrequestanimationframe/
It's a new API that's going to land in Fx4b4 that's designed to help
make animations smoother by letting you repaint them at the speed the
browser wants to, rather than having to guess at what it might be able
to. The usage is something like this:
var start= window.mozAnimationStartTime;
function step(event) {
var progress= event.timeStamp - start;
d.style.left = Math.min(progress/10, 200) + "px";
if (progress< 2000) {
window.mozRequestAnimationFrame();
}
}
window.addEventListener("MozBeforePaint", step, false);
window.mozRequestAnimationFrame()
Quoting from mozHacks, "Using this API has a few advantages, even in
this simple case. The author doesn't have to guess a timeout value. If
the browser is overloaded the animation will degrade gracefully instead
of uselessly running the step script more times than necessary. If the
page is in a hidden tab, we'll be able to throttle the frame rate down
to a very low value (e.g. one frame per second), saving CPU load."
What are people's thoughts? I realise that this isn't even an official
proposal yet, but do you think that there could be significant benefits
to this? Would MooTools benefit from this API, notwithstanding the
unified Fx timer that's coming soon?
--
Barry van Oudtshoorn
www.barryvan.com.au
Not sent from my Apple ?Phone.