-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation-amp.html
189 lines (174 loc) · 5.36 KB
/
animation-amp.html
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!doctype html>
<html amp='amp'>
<head>
<meta charset="utf-8">
<title>Animations Examples</title>
<link rel="canonical" href="amps.html" >
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-custom>
.buttons {
position: fixed;
bottom: 0;
left: 0;
right: 0;
}
.block {
width: 100px;
height: 100px;
display: block;
background: pink;
position: absolute;
top: 50px;
left: 10px;
z-index: 2;
--start-y: -240px;
--start-o: 0.1;
}
.rot-image {
--angle: 20deg;
--delay: 0.1s;
}
#image3 {
--angle: 10deg;
--delay: 0.4s;
}
.rain {
position: absolute;
top: -20px;
left: 0;
right: 0;
height: 0;
z-index: 1000;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: space-around;
align-items: center;
}
.drop {
width: 20px;
height: 20px;
background: rgba(0, 0, 0, 0.25);
border-radius: 50%;
}
@keyframes rotate {
100% {
transform: rotate(calc(var(--angle) * -3));
}
}
@supports (unknown: red) {
@keyframes rotate {
100% {
transform: rotate(calc(var(--angle) * -6));
}
}
}
</style>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-animation" src="https://cdn.ampproject.org/v0/amp-animation-0.1.js"></script>
</head>
<body>
<amp-animation id="anim1" layout="nodisplay" trigger="visibility">
<script type="application/json">
{
"duration": "1s",
"iterations": "4",
"fill": "both",
"direction": "alternate",
"animations": [
{
"media": "(max-width: 320px)",
"selector": ".rot-image",
"easing": "cubic-bezier(0,0,.21,1)",
"keyframes": {
"transform": "rotate(var(--angle))"
}
},
{
"media": "(min-width: 321px)",
"selector": ".rot-image",
"delay": "var(--delay)",
"easing": "cubic-bezier(0,0,.21,1)",
"keyframes": "rotate"
},
{
"animation": "anim2",
"selector": "#image2",
"easing": "cubic-bezier(0,0,.21,1)"
},
{
"animation": "anim-rain",
"--max-delay": "5s"
}
]
}
</script>
</amp-animation>
<amp-animation id="anim2" layout="nodisplay">
<script type="application/json">
{
"keyframes": [
{"transform": "translateX(calc(width('#image1') / 2)) translateY(var(--start-y))", "opacity": "var(--start-o)"},
{"transform": "translateY(calc(10% + 10px))", "opacity": "calc(var(--start-o) * 7)"}
]
}
</script>
</amp-animation>
<amp-animation id="anim-rain" layout="nodisplay">
<script type="application/json">
{
"selector": ".drop",
"--delay": "rand(0.1s, var(--max-delay))",
"delay": "var(--delay)",
"direction": "normal",
"subtargets": [
{
"index": 0,
"direction": "reverse"
},
{
"selector": ".antigrav",
"direction": "reverse",
"--delay": "0s"
}
],
"keyframes": {"transform": "translateY(120vh)"}
}
</script>
</amp-animation>
<div class="rain">
<div class="drop"></div>
<div class="drop"></div>
<div class="drop antigrav"></div>
<div class="drop"></div>
<div class="drop"></div>
<div class="drop"></div>
<div class="drop"></div>
</div>
<amp-img id="image1" class="rot-image"
src="img/sea@2x.jpg"
width=527 height=193 layout="responsive"></amp-img>
<amp-img id="image3" class="rot-image"
src="https://lh4.googleusercontent.com/-okOlNNHeoOc/VbYyrlFYFII/AAAAAAABYdA/La-3j3c-QQI/w1002-h367-no/PANO_20150726_171347%257E2.jpg"
width=527 height=193 layout="responsive"></amp-img>
<amp-img id="image2"
class="block"
layout="responsive" width="100" height="100"
src="img/hero@1x.jpg"></amp-img>
<a id="a1"></a>
<div class="buttons">
<button on="tap:anim1.start">Start</button>
<button on="tap:anim1.restart">Restart</button>
<button on="tap:anim1.restart(delay='-0.5s')">Restart at -0.5s</button>
<button on="tap:anim1.pause">Pause</button>
<button on="tap:anim1.resume">Resume</button>
<button on="tap:anim1.togglePause">Toggle Pause</button>
<button on="tap:anim1.seekTo(time=2000)">Seek to 500</button>
<button on="tap:anim1.seekTo(percent=0.5)">Seek to 50%</button>
<button on="tap:anim1.reverse">Reverse</button>
<button on="tap:anim1.finish">Finish</button>
<button on="tap:anim1.cancel">Cancel</button>
</div>
</body>
</html>