Skip to content

sroucheray/requestAnimationFrameRate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

window.requestAnimationFrameRate()

Sometimes you need to render at a specific frame rate.

When you use window.requestAnimation browsers make their best to call your function as fast as possible.

window.requestAnimationFrameRate() creates an intermediate function with the same signature as window.requestAnimation but being called at a specified frame rate.

Basic usage

// First you create a function with a specified frame rate, here 25 frames per second
var requestAnimationFrameAt25FPS = window.requestAnimationFrameRate(25)

// The render() function will be called at 25 frames per second
function render(){
    requestAnimationFrameAt25FPS(render);
    //Do anything you want every 25 frames per second
}

requestAnimationFrameAt25FPS(render);

Cancel usage

// Similar piece of code as in previous example
var requestAnimationFrameAt25FPS = window.requestAnimationFrameRate(25),
    requestID;
function render(){
    requestID = requestAnimationFrameAt25FPS(render);
    //Do anything you want every 25 frames per second
}

requestID = requestAnimationFrameAt25FPS(render);


// Any time a request is cancelable
window.cancelAnimationFrameRate(requestID)

About

Sometimes you need to render at a specific frame rate.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published