|
1 var currentOffset = null; |
|
2 var maxOffset = null; |
|
3 var property = "top"; |
|
4 |
|
5 var rfa = null; |
|
6 if (window.requestAnimationFrame) { |
|
7 rfa = requestAnimationFrame; |
|
8 } else if (window.mozRequestAnimationFrame) { |
|
9 rfa = mozRequestAnimationFrame; |
|
10 } else if (window.webkitRequestAnimationFrame) { |
|
11 rfa = webkitRequestAnimationFrame; |
|
12 } else if (window.msRequestAnimationFrame) { |
|
13 rfa = msRequestAnimationFrame; |
|
14 } else if (window.oRequestAnimationFrame) { |
|
15 rfa = oRequestAnimationFrame; |
|
16 } |
|
17 |
|
18 function animate(from, to, prop) { |
|
19 currentOffset = from; |
|
20 maxOffset = to; |
|
21 if (prop) { |
|
22 property = prop; |
|
23 } |
|
24 rfa(animateStep); |
|
25 } |
|
26 |
|
27 function animateStep() { |
|
28 if (currentOffset <= maxOffset) { |
|
29 document.getElementById("child").style[property] = currentOffset + "px"; |
|
30 currentOffset += 10; |
|
31 rfa(animateStep); |
|
32 } else { |
|
33 document.documentElement.removeAttribute("class"); |
|
34 } |
|
35 } |
|
36 |
|
37 function toAuto(prop) { |
|
38 if (prop) { |
|
39 property = prop; |
|
40 } |
|
41 rfa(setToAuto); |
|
42 } |
|
43 |
|
44 function setToAuto() { |
|
45 document.getElementById("child").style[property] = "auto"; |
|
46 document.documentElement.removeAttribute("class"); |
|
47 } |
|
48 |
|
49 function fromAuto(to, prop) { |
|
50 maxOffset = to; |
|
51 if (prop) { |
|
52 property = prop; |
|
53 } |
|
54 rfa(setFromAuto); |
|
55 } |
|
56 |
|
57 function setFromAuto() { |
|
58 document.getElementById("child").style[property] = maxOffset + "px"; |
|
59 document.documentElement.removeAttribute("class"); |
|
60 } |
|
61 |