Calculate FPS in Canvas using requestAnimationFrame

Do not use new Date() This API has several flaws and is only useful for getting the current date + time. Not for measuring timespans. The Date-API uses the operating system’s internal clock, which is constantly updated and synchronized with NTP time servers. This means, that the speed / frequency of this clock is sometimes … Read more

$(window).scroll in vanilla JavaScript

Question 1 window.onscroll = function() { console.log(‘scrolling’); }; or if your targeted browsers support addEventListener : window.addEventListener(‘scroll’, function() { console.log(‘scrolling’); }); Question 2 In my opinion, if you’re just scrolling from one section to a another section of your page, and not having some sort of constantly running scrolling movement, you’re fine doing this without … Read more

How to use requestAnimationFrame?

Warning! This question is not about the best way to shim requestAnimFrame. If you are looking for that, move on to any other answer on this page. You got tricked by automatic semicolon insertion. Try this: window.requestAnimFrame = function(){ return ( window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(/* function */ callback){ … Read more

Multiple requestAnimationFrame performance

I don’t think any of these answers really explained what I was looking for: “do n calls to requestAnimationFrame” get debounced (i.e. dequeued 1 per frame) or all get invoked in the next frame. When callbacks queued by requestAnimationFrame() begin to fire multiple callbacks in a single frame (mdn) This suggests the latter, multiple callbacks … Read more

scroll events: requestAnimationFrame VS requestIdleCallback VS passive event listeners

Although this question is a little bit older, I want to answer it because I often see scripts, where a lot of these techniques are misused. In general all your asked tools (rAF, rIC and passive listeners) are great tools and won’t vanish soon. But you have to know why to use them. Before I … Read more

Controlling fps with requestAnimationFrame?

How to throttle requestAnimationFrame to a specific frame rate Demo throttling at 5 FPS: http://jsfiddle.net/m1erickson/CtsY3/ This method works by testing the elapsed time since executing the last frame loop. Your drawing code executes only when your specified FPS interval has elapsed. The first part of the code sets some variables used to calculate elapsed time. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)