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
54 lines (42 loc) · 1.62 KB
/
raf.js
File metadata and controls
54 lines (42 loc) · 1.62 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict';
(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;
});
// .factory('$$animateReflow', function($$rAF, $document) {
// var bodyEl = $document[0].body;
// return function(fn) {
// //the returned function acts as the cancellation function
// return $$rAF(function() {
// //the line below will force the browser to perform a repaint
// //so that all the animated elements within the animation frame
// //will be properly updated and drawn on screen. This is
// //required to perform multi-class CSS based animations with
// //Firefox. DO NOT REMOVE THIS LINE.
// var a = bodyEl.offsetWidth + 1;
// fn();
// });
// };
// });