You can do the same you do with setInterval
, put your call to updateState in a closure.
function updateState() {
requestAnimFrame( function(){
if( oldValue < newValue ) {
updateState(oldValue += max/100);
}
});
// The rest of your code
}
updateState();