Call a function at every frame or every X ms. With start/stop
npm install intervalometer> Call a function at every frame or every X ms. With start/stop



There are two times of intervalometers: frame-based and time-based. Both return an object with start and stop functions. You can safely call start multiple times, the callback will only run once at every interval.
Uses requestAnimationFrame and therefore calls the provided callback at every frame. Ideal for animations
``js
const painter = frameIntervalometer(function (millisecondsSinceLastFrame) {
// your logic to run at every frame
});
button.onclick = function () {
painter.start();
};
`
uses setTimeout and calls the callback every ms milliseconds
`js
const poller = timerIntervalometer(pollingFunction, 100); //runs every 100 ms
startButton.onclick = function () {
poller.start();
};
stopButton.onclick = function () {
poller.stop();
};
`
Pick your favorite:
`html`
`sh`
npm install --save intervalometer
`js`
var i = require('intervalometer');
var frameIntervalometer = i.frameIntervalometer;
var timerIntervalometer = i.timerIntervalometer;
`js`
import {frameIntervalometer, timerIntervalometer} from 'intervalometer';
None! frameIntervalometer only works where window.requestAnimationFrame is available (yes in modern browsers; not in Node)
* iphone-inline-video: video[playsinline]` polyfill that uses this module.
* animate-prop: Single low-level function to tween any property over time.
MIT © Federico Brigante