记录前端学习

学习之路・Demo-01

因本人习惯,笔记在 WebStorm 上呈现

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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Demo01</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="./css/Demo01.css" charset="UTF-8">

</head>
<body>

<div class="textcontainer">
<span class="particletext bubbles">Bubbles</span>
</div>

<div class="textcontainer">
<span class="particletext confetti">Confetti</span>
</div>

<div class="textcontainer">
<span class="particletext hearts">Hearts</span>
</div>

<div class="textcontainer">
<span class="particletext fire">Fire</span>
</div>


<div class="textcontainer">
<span class="particletext lines">Lines</span>
</div>
<!--<div class="textcontainer">
<span class="particletext sunbeams">Beams?</span>
</div>-->

<script type="text/javascript" src="./js/Demo01.js" charset="UTF-8"></script>

</body>
</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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
body .textcontainer {
padding: 40px 0;
text-align: center;
}

body .particletext {
text-align: center;
font-size: 48px;
position: relative;
}

body .particletext.bubbles > .particle {
opacity: 0;
position: absolute;
background-color: rgba(33, 150, 243, 0.5);
-webkit-animation: bubbles 3s ease-in infinite;
animation: bubbles 3s ease-in infinite;
border-radius: 100%;
}

body .particletext.hearts > .particle {
opacity: 0;
position: absolute;
background-color: #cc2a5d;
-webkit-animation: hearts 3s ease-in infinite;
animation: hearts 3s ease-in infinite;
}

body .particletext.hearts > .particle:before, body .particletext.hearts > .particle:after {
position: absolute;
content: "";
border-radius: 100px;
top: 0px;
left: 0px;
width: 100%;
height: 100%;
background-color: #cc2a5d;
}

body .particletext.hearts > .particle:before {
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}

body .particletext.hearts > .particle:after {
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}

body .particletext.lines > .particle {
position: absolute;
background-color: rgba(244, 67, 54, 0.5);
-webkit-animation: lines 3s linear infinite;
animation: lines 3s linear infinite;
}

body .particletext.confetti > .particle {
opacity: 0;
position: absolute;
-webkit-animation: confetti 3s ease-in infinite;
animation: confetti 3s ease-in infinite;
}

body .particletext.confetti > .particle.c1 {
background-color: rgba(76, 175, 80, 0.5);
}

body .particletext.confetti > .particle.c2 {
background-color: rgba(156, 39, 176, 0.5);
}

body .particletext.fire > .particle {
position: absolute;
background-color: rgba(255, 193, 7, 0.5);
border-radius: 40px;
border-top-right-radius: 0px;
-webkit-animation: fires 0.8s linear infinite;
animation: fires 0.8s linear infinite;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
opacity: 0;
}

body .particletext.fire > .particle:before {
position: absolute;
content: "";
top: 60%;
left: 40%;
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 50%;
height: 50%;
border-radius: 40px;
border-top-right-radius: 0px;
background-color: rgba(251, 140, 0, 0.5);
}

body .particletext.sunbeams > .particle {
position: absolute;
background-color: rgba(253, 216, 53, 0.5);
-webkit-animation: sunbeams 3s linear infinite;
animation: sunbeams 3s linear infinite;
}

@-webkit-keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
@keyframes bubbles {
0% {
opacity: 0;
}
20% {
opacity: 1;
-webkit-transform: translate(0, -20%);
transform: translate(0, -20%);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%);
transform: translate(0, -1000%);
}
}
@-webkit-keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
@keyframes hearts {
0% {
opacity: 0;
-webkit-transform: translate(0, 0%) rotate(45deg);
transform: translate(0, 0%) rotate(45deg);
}
20% {
opacity: 0.8;
-webkit-transform: translate(0, -20%) rotate(45deg);
transform: translate(0, -20%) rotate(45deg);
}
100% {
opacity: 0;
-webkit-transform: translate(0, -1000%) rotate(45deg);
transform: translate(0, -1000%) rotate(45deg);
}
}
@-webkit-keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
@keyframes lines {
0%, 50%, 100% {
-webkit-transform: translateY(0%);
transform: translateY(0%);
}
25% {
-webkit-transform: translateY(100%);
transform: translateY(100%);
}
75% {
-webkit-transform: translateY(-100%);
transform: translateY(-100%);
}
}
@-webkit-keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
@keyframes confetti {
0% {
opacity: 0;
-webkit-transform: translateY(0%) rotate(0deg);
transform: translateY(0%) rotate(0deg);
}
10% {
opacity: 1;
}
35% {
-webkit-transform: translateY(-800%) rotate(270deg);
transform: translateY(-800%) rotate(270deg);
}
80% {
opacity: 1;
}
100% {
opacity: 0;
-webkit-transform: translateY(2000%) rotate(1440deg);
transform: translateY(2000%) rotate(1440deg);
}
}
@-webkit-keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
@keyframes fires {
0% {
-webkit-transform: rotate(-70deg) translateY(0%);
transform: rotate(-70deg) translateY(0%);
}
25% {
-webkit-transform: rotate(-20deg) translateY(-5%);
transform: rotate(-20deg) translateY(-5%);
opacity: 1;
}
50% {
-webkit-transform: rotate(-70deg) translateY(-10%);
transform: rotate(-70deg) translateY(-10%);
}
75% {
-webkit-transform: rotate(-20deg) translateY(-20%);
transform: rotate(-20deg) translateY(-20%);
}
100% {
-webkit-transform: rotate(-70deg) translateY(-40%);
transform: rotate(-70deg) translateY(-40%);
opacity: 1;
}
}
@-webkit-keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%, 14%, 17%, 43%, 53%, 71%, 80%, 94%, 100% {
opacity: 0;
}
6%, 15%, 24%, 28%, 48%, 55%, 78%, 82%, 99% {
opacity: 1;
}
}
@keyframes sunbeams {
0% {
-webkit-transform: translateY(40%) rotate(0deg);
transform: translateY(40%) rotate(0deg);
}
50% {
-webkit-transform: translateY(-40%) rotate(180deg);
transform: translateY(-40%) rotate(180deg);
}
100% {
-webkit-transform: translateY(40%) rotate(360deg);
transform: translateY(40%) rotate(360deg);
}
0%, 14%, 17%, 43%, 53%, 71%, 80%, 94%, 100% {
opacity: 0;
}
6%, 15%, 24%, 28%, 48%, 55%, 78%, 82%, 99% {
opacity: 1;
}
}
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
function initparticles() {
bubbles();
hearts();
lines();
confetti();
fire();
sunbeams();
}

/*The measurements are ... whack (so to say), for more general text usage I would generate different sized particles for the size of text; consider this pen a POC*/

function bubbles() {
$.each($(".particletext.bubbles"), function(){
var bubblecount = ($(this).width()/50)*10;
for(var i = 0; i <= bubblecount; i++) {
var size = ($.rnd(40,80)/10);
$(this).append('<span class="particle" style="top:' + $.rnd(20,80) + '%; left:' + $.rnd(0,95) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + ($.rnd(0,30)/10) + 's;"></span>');
}
});
}

function hearts() {
$.each($(".particletext.hearts"), function(){
var heartcount = ($(this).width()/50)*5;
for(var i = 0; i <= heartcount; i++) {
var size = ($.rnd(60,120)/10);
$(this).append('<span class="particle" style="top:' + $.rnd(20,80) + '%; left:' + $.rnd(0,95) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + ($.rnd(0,30)/10) + 's;"></span>');
}
});
}

function lines() {
$.each($(".particletext.lines"), function(){
var linecount = ($(this).width()/50)*10;
for(var i = 0; i <= linecount; i++) {
$(this).append('<span class="particle" style="top:' + $.rnd(-30,30) + '%; left:' + $.rnd(-10,110) + '%;width:' + $.rnd(1,3) + 'px; height:' + $.rnd(20,80) + '%;animation-delay: -' + ($.rnd(0,30)/10) + 's;"></span>');
}
});
}

function confetti() {
$.each($(".particletext.confetti"), function(){
var confetticount = ($(this).width()/50)*10;
for(var i = 0; i <= confetticount; i++) {
$(this).append('<span class="particle c' + $.rnd(1,2) + '" style="top:' + $.rnd(10,50) + '%; left:' + $.rnd(0,100) + '%;width:' + $.rnd(6,8) + 'px; height:' + $.rnd(3,4) + 'px;animation-delay: ' + ($.rnd(0,30)/10) + 's;"></span>');
}
});
}

function fire() {
$.each($(".particletext.fire"), function(){
var firecount = ($(this).width()/50)*20;
for(var i = 0; i <= firecount; i++) {
var size = $.rnd(8,12);
$(this).append('<span class="particle" style="top:' + $.rnd(40,70) + '%; left:' + $.rnd(-10,100) + '%;width:' + size + 'px; height:' + size + 'px;animation-delay: ' + ($.rnd(0,20)/10) + 's;"></span>');
}
});
}

function sunbeams() {
$.each($(".particletext.sunbeams"), function(){
var linecount = ($(this).width()/50)*10;
for(var i = 0; i <= linecount; i++) {
$(this).append('<span class="particle" style="top:' + $.rnd(-50,0) + '%; left:' + $.rnd(0,100) + '%;width:' + $.rnd(1,3) + 'px; height:' + $.rnd(80,160) + '%;animation-delay: -' + ($.rnd(0,30)/10) + 's;"></span>');
}
});
}

jQuery.rnd = function(m,n) {
m = parseInt(m);
n = parseInt(n);
return Math.floor( Math.random() * (n - m + 1) ) + m;
}

initparticles();


效果

效果

学习心得

  • Ctrl+C,Ctrl+V 的确很舒服
  • 了解了运行逻辑