-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
74 lines (66 loc) · 1.71 KB
/
main.js
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
let html = document.querySelector('#html');
let style = document.querySelector("#style");
let string = `/* 你好,我叫Joyce
* 首先准备一个div
**/
#div1 {
border: 1px solid green;
height: 200px;
width: 200px;
}
/* 接下来,将这个div变成一个八卦图
* 首先变成一个圆
**/
#div1 {
border-radius: 50%;
box-shadow: 0 0 3px rgba(0,0,0,0.5);
border: none;
}
/* 八卦是阴阳形成的
* 一半黑一半白
**/
#div1 {
background: linear-gradient(90deg, rgba(255,255,255,1) 0%, rgba(255,255,255,1) 50%, rgba(0,0,0,1) 50%, rgba(0,0,0,1) 100%);
}
/* 加上两颗小球 */
#div1::after {
width: 100px;
height: 100px;
top: 0;
left: 50%;
transform: translateX(-50%);
border-radius: 50%;
background: radial-gradient(circle, rgba(255,255,255,1) 0%, rgba(255,255,255,1) 25%, rgba(0,0,0,1) 25%, rgba(0,0,0,1) 100%);
}
#div1::before {
width: 100px;
height: 100px;
bottom: 0;
left: 50%;
transform: translateX(-50%);
border-radius: 50%;
background: radial-gradient(circle, rgba(0,0,0,1) 0%, rgba(0,0,0,1) 25%, rgba(255,255,255,1) 25%, rgba(255,255,255,1) 100%);
}
`;
let string2 = "";
let n = 0;
let step = () => {
setTimeout(()=> {
if( string[n] === "\n") {
string2 += "<br>"; // 展示html里的回车
} else if( string[n] === " ") {
string2 += " "; // 展示html里的空格
} else {
string2 += string[n];
}
html.innerHTML = string2;
style.innerHTML = string.substring(0,n);
window.scrollTo(0,10000);
html.scrollTo(0,10000);
if( n < string.length - 1) {
n += 1;
step();
}
}, 0);
};
step();