1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | (function() {
|
12 | 'use strict';
|
13 |
|
14 | if (!Date.now) {
|
15 | |
16 |
|
17 |
|
18 |
|
19 | Date.now = function() { return new Date().getTime(); };
|
20 | Date['now'] = Date.now;
|
21 | }
|
22 |
|
23 | var vendors = ['webkit', 'moz'];
|
24 | for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) {
|
25 | var vp = vendors[i];
|
26 | window.requestAnimationFrame = window[vp + 'RequestAnimationFrame'];
|
27 | window.cancelAnimationFrame = (window[vp + 'CancelAnimationFrame'] ||
|
28 | window[vp + 'CancelRequestAnimationFrame']);
|
29 | window['requestAnimationFrame'] = window.requestAnimationFrame;
|
30 | window['cancelAnimationFrame'] = window.cancelAnimationFrame;
|
31 | }
|
32 |
|
33 | if (/iP(ad|hone|od).*OS 6/.test(window.navigator.userAgent) || !window.requestAnimationFrame || !window.cancelAnimationFrame) {
|
34 | var lastTime = 0;
|
35 | |
36 |
|
37 |
|
38 |
|
39 | window.requestAnimationFrame = function(callback) {
|
40 | var now = Date.now();
|
41 | var nextTime = Math.max(lastTime + 16, now);
|
42 | return setTimeout(function() { callback(lastTime = nextTime); },
|
43 | nextTime - now);
|
44 | };
|
45 | window.cancelAnimationFrame = clearTimeout;
|
46 | window['requestAnimationFrame'] = window.requestAnimationFrame;
|
47 | window['cancelAnimationFrame'] = window.cancelAnimationFrame;
|
48 | }
|
49 |
|
50 | })();
|