forked from mgcrea/angular-strap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathraf.js
More file actions
37 lines (29 loc) · 1.07 KB
/
raf.js
File metadata and controls
37 lines (29 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
if (angular.version.minor < 3 && angular.version.dot < 14) {
angular.module('ng')
.factory('$$rAF', function ($window, $timeout) {
var requestAnimationFrame = $window.requestAnimationFrame ||
$window.webkitRequestAnimationFrame ||
$window.mozRequestAnimationFrame;
var cancelAnimationFrame = $window.cancelAnimationFrame ||
$window.webkitCancelAnimationFrame ||
$window.mozCancelAnimationFrame ||
$window.webkitCancelRequestAnimationFrame;
var rafSupported = !!requestAnimationFrame;
var raf = rafSupported ?
function (fn) {
var id = requestAnimationFrame(fn);
return function () {
cancelAnimationFrame(id);
};
} :
function (fn) {
var timer = $timeout(fn, 16.66, false); // 1000 / 60 = 16.666
return function () {
$timeout.cancel(timer);
};
};
raf.supported = rafSupported;
return raf;
});
}