-
Notifications
You must be signed in to change notification settings - Fork 15
/
ya_animation3.html
212 lines (171 loc) · 5.22 KB
/
ya_animation3.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html>
<head>
<title>
CSS ANIMATION
</title>
<style>
/* Animation properties */
.star {
animation: star 10s ease-out infinite;
}
.wars {
animation: wars 10s ease-out infinite;
}
.byline span {
animation: spin-letters 10s linear infinite;
}
.byline {
animation: move-byline 10s linear infinite;
}
/* Keyframes */
@keyframes star {
0% {
opacity: 0;
transform: scale(1.5) translateY(-0.75em);
}
20% {
opacity: 1;
}
89% {
opacity: 1;
transform: scale(1);
}
100% {
opacity: 0;
transform: translateZ(-1000em);
}
}
@keyframes wars {
0% {
opacity: 0;
transform: scale(1.5) translateY(0.5em);
}
20% {
opacity: 1;
}
90% {
opacity: 1;
transform: scale(1);
}
100% {
opacity: 0;
transform: translateZ(-1000em);
}
}
@keyframes spin-letters {
0%,
10% {
opacity: 0;
transform: rotateY(90deg);
}
30% {
opacity: 1;
}
70%,
86% {
transform: rotateY(0);
opacity: 1;
}
95%,
100% {
opacity: 0;
}
}
@keyframes move-byline {
0% {
transform: translateZ(5em);
}
100% {
transform: translateZ(0);
}
}
/* Make the 3D work on the container */
.starwars-demo {
perspective: 800px;
transform-style: preserve3d;
}
/* General styles and layout */
body {
background: #000 url(//cssanimation.rocks/demo/starwars/images/bg.jpg);
}
.starwars-demo {
height: 17em;
left: 50%;
position: absolute;
top: 53%;
transform: translate(-50%, -50%);
width: 34em;
}
.byline span {
display: inline-block;
}
img {
width: 100%;
}
.star,
.wars,
.byline {
position: absolute;
}
.star {
top: -0.75em;
}
.wars {
bottom: -0.5em;
}
.byline {
color: #fff;
font-family: "ITC Serif Gothic", Lato;
font-size: 2.25em;
left: -2em;
letter-spacing: 0.4em;
right: -2em;
text-align: center;
text-transform: uppercase;
top: 29%;
}
/*** Media queries for adjusting to different screen sizes ***/
@media only screen and (max-width: 600px) {
.starwars-demo {
font-size: 10px;
}
}
@media only screen and (max-width: 480px) {
.starwars-demo {
font-size: 7px;
}
}
</style>
</head>
<body>
<div class="starwars-demo">
<img src="//cssanimation.rocks/demo/starwars/images/star.svg" alt="Star" class="star">
<img src="//cssanimation.rocks/demo/starwars/images/wars.svg" alt="Wars" class="wars">
<h2 class="byline" id="byline">The Force Awakens</h2>
</div>
<script>
/* Learn how to create this and much more with this email course:
https://cssanimation.rocks/courses/animation-101/
MANY THANKS TO @tadywankenobi for the following JS to handle the text in the byline:
The following JS takes in the byline and splits it into letters, each one wrapped in a span. We need to create the spans as nodes, we can't just add them to the HTML using innerHTML, as to do so would mean the CSS won't affect the span because it doesn't recognise the tag as existing. It's an old problem we run into time and again.
*/
var byline = document.getElementById('byline'); // Find the H2
bylineText = byline.innerHTML; // Get the content of the H2
bylineArr = bylineText.split(''); // Split content into array
byline.innerHTML = ''; // Empty current content
var span; // Create variables to create elements
var letter;
for (i = 0; i < bylineArr.length; i++) { // Loop for every letter
span = document.createElement("span"); // Create a <span> element
letter = document.createTextNode(bylineArr[i]); // Create the letter
if (bylineArr[i] == ' ') { // If the letter is a space...
byline.appendChild(letter); // ...Add the space without a span
} else {
span.appendChild(letter); // Add the letter to the span
byline.appendChild(span); // Add the span to the h2
}
}
</script>
</body>
</html>