Skip to content

Commit

Permalink
Raf polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier de Jong authored and Olivier de Jong committed Oct 4, 2017
1 parent 8c36819 commit 088dbf1
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
32 changes: 32 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "raf-polyfill",
"version": "1.0.0",
"description": "Yet Another RequestAnimationFrame Polyfill",
"main": "raf.js",
"files": [
"raf.js",
"raf.min.js",
"README.md"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/airwave-development/raf-polyfill.git"
},
"keywords": [
"requestanimationframe",
"raf",
"polyfill",
"react",
"reactjs"
],
"author": "Airwave",
"license": "MIT",
"bugs": {
"url": "https://github.com/airwave-development/raf-polyfill/issues"
},
"homepage": "https://github.com/airwave-development/raf-polyfill#readme",
"devDependencies": {}
}
28 changes: 28 additions & 0 deletions raf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(function(window) {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];

for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
}

if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function(callback, element) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
var id = window.setTimeout(function() {
callback(currTime + timeToCall);
}, timeToCall);

lastTime = currTime + timeToCall;
return id;
};
}

if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = function(id) {
clearTimeout(id);
};
}
}(window));
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


0 comments on commit 088dbf1

Please sign in to comment.