You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
setInterval is usually pretty poor for timing things.
You should get better performance by using requestAnimationFrame(). This will run at a maximum of 60fps, depending on how "busy" the rest of the system is. The latter qualification is also true of setInterval of course since javascript is single threaded.
In general you would do something like this:
functionrequestInterval(fn,ms){varhandle={value: null};vartimeStart=newDate().getTime();varrafFn=function(){vartimeNow=newDate().getTime();if(timeNow>=timeStart+ms){fn();timeStart=timeNow;// or maybe timeStart += ms?}handle.value=requestAnimationFrame(rafFn);};handle.value=requestAnimationFrame(rafFn);returnhandle;}// use it:varhandle=requestInterval(function(){console.log(Date.now());},1000);// cancel it:cancelAnimationFrame(handle.value);
I haven't tested that code, and I also assume that requestAnimationFrame is unprefixed. There are decent shims out there you could look at to, such as:
That would have made things a lot easier. I'll have to try that out when I have a chance...which is probably either this weekend or next. Sr. Design/School work has me swamped.
Hi,
setInterval is usually pretty poor for timing things.
You should get better performance by using requestAnimationFrame(). This will run at a maximum of 60fps, depending on how "busy" the rest of the system is. The latter qualification is also true of setInterval of course since javascript is single threaded.
In general you would do something like this:
I haven't tested that code, and I also assume that requestAnimationFrame is unprefixed. There are decent shims out there you could look at to, such as:
https://gist.github.com/joelambert/1002116
The text was updated successfully, but these errors were encountered: