Skip to content

julienetie/set-animation-interval

Repository files navigation

setAnimationInterval()

Repeatedly call a function without setInterval, call a function by approximate frames per second

  • npm i --save set-animation-interval = A better performing setInterval with frames per second
    also...
  • npm i --save set-animation-frame = A better performing setTimeout
// Heads up!
// Animation timing functions work in enviroments that either render or 
// simulate the rendering of frames. (Unlike nodejs & dev tools)

Usage:

var requestID = setAnimationInterval(<Callback>, <delay>, <useFPS>);
  • Callback : The function to be executed between each delay.

  • delay : The delay in milliseconds or frames per second if useFPS is truthy.

  • useFPS : If true, the delay value is interpreted by FPS. It is false by defualt.

  • setAnimationInterval returns the requestID for cancellation via cancelRequestAnimationFrame() (polyfill).

  • setAnimationInterval passes the given function the DOMHighResTimeStamp as a parameter.

Why avoid setInterval?

Checkout requestAnimationFrame for Smart Animating By Paul Irish


Browser support using the requestFrame polyfill. npm i --save request-frame

  • IE 5.5+

Browser Support Without a polyfill or vendor prefix usage.

  • IE10+

See caniuse for more details.

MIT License

Copyright (c) 2016 Julien Etienne

About

Repeatedly call a function by milliseconds or FPS without setInterval

Resources

License

Stars

Watchers

Forks

Packages

No packages published