interactjs
Version:
Drag and drop, resizing and multi-touch gestures with inertia and snapping for modern browsers (and also IE8+)
35 lines (28 loc) • 826 B
JavaScript
const { window } = require('./window');
const vendors = ['ms', 'moz', 'webkit', 'o'];
let lastTime = 0;
let request;
let cancel;
for (let x = 0; x < vendors.length && !window.requestAnimationFrame; x++) {
request = window[vendors[x] + 'RequestAnimationFrame'];
cancel = window[vendors[x] +'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
}
if (!request) {
request = function (callback) {
const currTime = new Date().getTime();
const timeToCall = Math.max(0, 16 - (currTime - lastTime));
const id = setTimeout(function () { callback(currTime + timeToCall); },
timeToCall);
lastTime = currTime + timeToCall;
return id;
};
}
if (!cancel) {
cancel = function (id) {
clearTimeout(id);
};
}
module.exports = {
request,
cancel,
};