-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
420 lines (376 loc) · 10.3 KB
/
index.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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="theme-color" content="#FFF" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1,minimum-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover" />
<title>520 节日快乐~</title>
<meta name="title" content="520 节日快乐" />
<!-- <link type="text/css" rel="stylesheet" href="./style.css"> -->
<style>
:root {
--dark-green: #066406;
--light-green: #338f37;
--light-pink: #dc4c70;
--medium-pink: #d52d58;
--dark-pink: #ca2850;
--light-brown: #ede3d2;
--dark-brown: #73592e;
--text-code: #edecee;
--bg-code: #333;
--rose-height: 350px;
--rose-width: 200px;
}
@font-face {
font-family: 'JetBrains Mono';
src: url('https://gw.alipayobjects.com/os/k/app/JetBrainsMono-Regular.ttf') format('truetype');
}
* {
font-family: JetBrains Mono, SF Mono, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Helvetica Neue, Helvetica, Arial, sans-serif;
}
body {
height: 100vh;
color: var(--light-pink);
background: var(--bg-code);
margin: 0;
font-size: 14px;
line-height: 1.4;
}
pre em {
font-style: normal;
}
.selector,
.selector .key {
color: var(--medium-pink);
}
.key {
color: var(--text-code);
}
.comment {
color: var(--light-pink);
}
.value {
color: var(--dark-browrn)
}
.dead-petals > div {
position: absolute;
height: 10px;
width: 20px;
top: 25%;
border-radius: 0 20px;
transition-timing-function: ease-out;
}
@keyframes rotate-petal {
0% {
transform: rotate(-45deg) translateY(0%);
top: 20%;
}
50% {
transform: rotate(45deg) translateY(-50%);
top: 50%;
}
100% {
transform: rotate(-45deg) translateY(0%);
top: 90%;
}
}
</style>
<style>
</style>
</head>
<body>
<script>
let styles = `\
/*
* Hello, 小妖怪!
* 今天是 520 呢,有收到玫瑰吗?
* 如果你没有收到,那我给你画一朵!
*/
/* 先搞一个写代码地方 */
pre {
color: #fff;
width: 100%;
height: 100%;
position: absolute;
top: 0;
box-sizing: border-box;
padding: 24px 16px;
margin-top: 0;
overflow-y: auto;
transition: all 500ms;
}
/* 为了更好地画玫瑰,我们把代码移到下面来 */
pre {
top: 60vh;
height: 40vh;
}
.container {
position: absolute;
top: 0;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 60vh;
margin: auto;
background: var(--light-brown);
overflow: hidden;
}
.rose {
margin: auto;
height: var(--rose-height);
width: 200px;
position: relative;
}
/* 让我们先来画一根笔直的,绿色的花茎!*/
.stem {
position: absolute;
height: 0;
width: 6px;
background: var(--dark-green);
bottom: 10%;
left: 50%;
margin-left: -3px;
border-radius: 0 0 3px 3px;
transition: height 1s;
}
.stem {
height: 200px;
}
/* 所谓带刺的玫瑰,怎么能不画点刺呢 ?*/
.thorns > div {
width: 0;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
position: absolute;
transition: all 0.2s;
}
/* 一个刺 */
.thorns > div:first-child {
left: 44%;
top: 50%;
border-right: 10px solid var(--dark-green);
}
/* 两个刺 */
.thorns > div:nth-child(2) {
left: 51%;
top: 62%;
border-left: 10px solid var(--dark-green);
}
/* 三个刺,真疼!*/
.thorns > div:nth-child(3) {
left: 44%;
top: 75%;
border-right: 10px solid var(--dark-green);
}
/* 接下来,让我们画叶子吧~ lalala~ */
.leaves > div {
position: absolute;
height: 60px;
width: 35px;
}
/* 我要画第一片叶子啦 */
.leaves > div:first-child {
top: 58%;
left: 28%;
border-radius: 0 30px 0 30px;
transform: rotate(-20deg);
transition: background 1s, box-shadow 1s 1s;
background: var(--dark-green);
box-shadow: inset 5px 5px var(--light-green);
}
/* 再画第二片叶子 */
.leaves > div:nth-child(2) {
border-radius: 30px 0 30px 0;
transform: rotate(20deg);
top: 45%;
right: 28%;
transition: background 1s, box-shadow 1s 1s;
background: var(--dark-green);
box-shadow: inset -5px 5px var(--light-green);
}
/*
* 好啦!终于可以画花啦!嘿嘿嘿!
* 先把中间的花芯画好~
*/
.petals > div:first-child {
top: 15%;
left: 50%;
margin-left: -25px;
position: absolute;
height: 100px;
width: 50px;
border-radius: 10px 10px 20px 20px;
transition: background 1s;
background: var(--light-pink);
}
.petals > div:not(:first-child) {
position: absolute;
height: 100px;
width: 40px;
}
/* 接下来画第二瓣花瓣 */
.petals > div:nth-child(2) {
top: 15%;
left: 30%;
transform-origin: bottom right;
border-radius: 0 35px 0 35px;
transition: background 1s, transform 1s 1s;
background: var(--medium-pink);
transform: rotate(-6deg);
}
/* 然后是第三瓣 */
.petals > div:nth-child(3) {
top: 15%;
right: 30%;
transform-origin: bottom left;
border-radius: 35px 0 35px 0;
transition: background 1s, transform 1s 1s;
background: var(--medium-pink);
transform: rotate(6deg);
}
/* 第四瓣花瓣 */
.petals > div:nth-child(4) {
top: 15%;
left: 30%;
transform: rotate(-18deg);
transform-origin: bottom right;
border-radius: 0 35px 0 35px;
transition: background 1s, transform 1s 1s;
background: var(--dark-pink);
}
/* 还有最后一瓣, 马上就要画好啦 */
.petals > div:nth-child(5) {
top: 15%;
right: 30%;
transform: rotate(18deg);
transform-origin: bottom left;
border-radius: 35px 0 35px 0;
transition: background 1s, transform 1s 1s;
background: var(--dark-pink);
}
/*
* 古人云:花开堪折直须折,你不折它就要掉光啦
*/
.dead-petals > div:first-child {
animation: rotate-petal 6s linear infinite;
left: 35%;
background: var(--medium-pink);
}
.dead-petals > div:nth-child(2) {
animation: rotate-petal 8s linear infinite;
left: 50%;
background: var(--dark-pink);
}
/* 加个罩子保护起来 */
.glass {
position: absolute;
transition: opacity 1s;
opacity: 0;
height: var(--rose-height);
width: var(--rose-width);
padding: 0 40px;
background: rgba(255, 250, 250, 0);
box-shadow: 0 -3px 5px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(2.8px);
-webkit-backdrop-filter: blur(2.8px);
border-bottom: 0;
border-radius: 5px;
border-top-right-radius: 40%;
border-top-left-radius: 40%;
opacity: 1;
}
/*
* 噔噔!就是这样,画好啦!
* 不知道你喜不喜欢,hhh
* 祝你 520 快乐!
* 要开心呀!
*/
`;
let template = `
\<style id="style-tag"></style>
<div class="container">
<div class="glass"></div>
<div class="rose">
<div class="stem"></div>
<div class="thorns">
<div></div>
<div></div>
<div></div>
</div>
<div class="leaves">
<div></div>
<div></div>
</div>
<div class="dead-petals">
<div></div>
<div></div>
</div>
<div class="petals">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
</div>
<pre id="style-text"></pre>\
`
const getStyleHtml = function () {
return document.getElementById('style-text').innerHTML;
};
let openComment = false;
const writeStyleChar = function (which) {
if (which === '/' && !openComment) {
openComment = true;
styles = getStyleHtml() + which;
} else if (which === '/' && openComment) {
openComment = false;
styles = getStyleHtml().replace(
/(\/[^\/]*\*)$/,
'<em class="comment">$1/</em>',
);
} else if (which === ':') {
styles = getStyleHtml().replace(
/([a-zA-Z- ^\n]*)$/,
'<em class="key">$1</em>:',
);
} else if (which === ';') {
styles = getStyleHtml().replace(
/([^:]*)$/,
'<em class="value">$1</em>;',
);
} else if (which === '{') {
styles = getStyleHtml().replace(
/(.*)$/,
'<em class="selector">$1</em>{',
);
} else {
styles = getStyleHtml() + which;
}
document.getElementById('style-text').innerHTML = styles;
document.getElementById('style-tag').insertAdjacentHTML('beforeend', which);
};
const writeStyles = function (message, index, interval) {
if (index < message.length) {
const pre = document.getElementById('style-text');
pre.scrollTop = pre.scrollHeight;
writeStyleChar(message[index++]);
return setTimeout(
() => writeStyles(message, index, interval),
interval,
);
}
};
const writeAllStyles = function() {
document.getElementById('style-text').innerHTML = styles;
document.getElementById('style-tag').insertAdjacentHTML('beforeend', styles);
}
document.body.insertAdjacentHTML('beforeend', template);
writeStyles(styles, 0, 24);
/* writeAllStyles(); */
</script>
</body>
</html>