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
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
const poller = timerIntervalometer(pollingFunction, 100); //runs every 100 ms
startButton.onclick = function () {
poller.start();
};
stopButton.onclick = function () {
poller.stop();
};
Pick your favorite:
<script src="dist/intervalometer.browser.js"></script>
<!-- use as intervalometer.frameIntervalometer(cb) -->
<!-- or intervalometer.timerIntervalometer(cb, ms) -->
npm install --save intervalometer
var i = require('intervalometer');
var frameIntervalometer = i.frameIntervalometer;
var timerIntervalometer = i.timerIntervalometer;
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