|
15 | 15 |
|
16 | 16 | // MIT license
|
17 | 17 |
|
| 18 | +(function(){ |
| 19 | + |
| 20 | + 'use strict'; |
18 | 21 |
|
19 |
| -'use strict'; |
20 |
| - |
21 |
| -if(!Date.now) { |
22 |
| - Date.now = function() { return new Date().getTime(); }; |
23 |
| -} |
24 |
| - |
25 |
| -var vendors = ['webkit', 'moz']; |
26 |
| -for(var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) { |
27 |
| - var vp = vendors[i]; |
28 |
| - window.requestAnimationFrame = window[vp + 'RequestAnimationFrame']; |
29 |
| - window.cancelAnimationFrame = (window[vp + 'CancelAnimationFrame'] || |
30 |
| - window[vp + 'CancelRequestAnimationFrame']); |
31 |
| -} |
32 |
| -if(/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) || // iOS6 is buggy |
33 |
| - !window.requestAnimationFrame || !window.cancelAnimationFrame) { |
| 22 | + if(!Date.now) { |
| 23 | + Date.now = function() { return (new Date()).getTime(); }; |
| 24 | + } |
| 25 | + |
| 26 | + var vendors = ['webkit', 'moz']; |
| 27 | + var i = 0; |
| 28 | + var l = vendors.length; |
| 29 | + var vp; |
34 | 30 | var lastTime = 0;
|
35 |
| - window.requestAnimationFrame = function(callback) { |
36 |
| - var now = Date.now(); |
37 |
| - var nextTime = Math.max(lastTime + 16, now); |
38 |
| - return setTimeout(function() { callback(lastTime = nextTime); }, |
39 |
| - nextTime - now); |
40 |
| - }; |
41 |
| - window.cancelAnimationFrame = clearTimeout; |
42 |
| -} |
| 31 | + |
| 32 | + for(; i < l && !window.requestAnimationFrame; ++i) { |
| 33 | + vp = vendors[i]; |
| 34 | + window.requestAnimationFrame = window[vp + 'RequestAnimationFrame']; |
| 35 | + window.cancelAnimationFrame = (window[vp + 'CancelAnimationFrame'] || |
| 36 | + window[vp + 'CancelRequestAnimationFrame']); |
| 37 | + } |
| 38 | + |
| 39 | + if(/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) || // iOS6 is buggy |
| 40 | + !window.requestAnimationFrame || !window.cancelAnimationFrame) { |
| 41 | + window.requestAnimationFrame = function(callback) { |
| 42 | + var now = Date.now(); |
| 43 | + var nextTime = Math.max(lastTime + 16, now); |
| 44 | + return setTimeout(function() { callback(lastTime = nextTime); }, |
| 45 | + nextTime - now); |
| 46 | + }; |
| 47 | + window.cancelAnimationFrame = clearTimeout; |
| 48 | + } |
| 49 | + |
| 50 | + vendors = null; |
| 51 | + i = null; |
| 52 | + l = null; |
| 53 | + vp = null; |
| 54 | + |
| 55 | +}()); |
0 commit comments