Archivi tag: requestAnimationFrame

Use RequestAnimationFrame with setTimeout-like function

Introduction

In this article I’ll show how to use jsTimers-rAF, a library that makes use of RequestAnimationFrame simply as the use of setTimeout or setInterval function.

In github there’re some examples of use, but now I’ll show how to use the library to change the background on the page, as a div, or what else you can imagine to do with requestAnimationFrame. Continue reading Use RequestAnimationFrame with setTimeout-like function

Request Animation Frame polyfill for Firefox nightly

Recently I tried a script uses Request Animation Frame with jsTimers-rAF-hack on firefox nightly and I saw  it doesn’t work. I debugged and I saw requestAnimationFrame into window object, but cancelAnimationFrame doesn’t, so the find browser methods doesn’t work fine.

So this is Erik Möller polyfill find browser methods fixed

var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length 
     && (window.requestAnimationFrame===undefined || 
       window.cancelAnimationFrame === undefined);
 ++x) {
     if(window.requestAnimationFrame === undefined)
         window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
     if(window.cancelAnimationFrame === undefined)
         window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
}

if (!window.requestAnimationFrame)
    //do some thing