forked from will0101/www
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimation-2.html
49 lines (45 loc) · 1.56 KB
/
animation-2.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
<script>
const commands3 = [
{ input: '$ node --version<br>', output: `v19.3.0<br><br>` },
{ input: `$ cat <<EOF >>my-project/README.md<br>`, output: `# Dependencies<br>
| Project | Version |<br>
|------------|---------|<br>
| nodejs.org | ^18.4 |<br>
EOF
<br><br>` },
{ input: '$ cd my-project<br>', output: `my-project<br><br>` },
{ input: '$ node --version<br>', output: `v18.13.0` },
];
let commandIndex3 = 0;
let command3 = commands3[commandIndex3];
let commandOutput3 = '';
function typeCommand3() {
if (commandIndex3 === commands3.length) {
return;
}
if (command3.input.length === 0) {
commandOutput3 += '\n' + command3.output + '\n';
document.querySelector('#terminal-output-3').innerHTML = commandOutput3;
commandIndex3++;
command3 = commands3[commandIndex3];
setTimeout(typeCommand3, 1500);
return;
}
let char = command3.input[0];
if (char === '$') {
char = '<span class="purple">$</span>';
}
commandOutput3 += char;
command3.input = command3.input.slice(1);
document.querySelector('#terminal-output-3').innerHTML = commandOutput3;
setTimeout(typeCommand3, Math.floor(Math.random() * (150 - 70) + 70));
}
const terminalOutput = document.querySelector('#terminal-output-3');
const observer = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting) {
typeCommand3();
observer.unobserve(terminalOutput);
}
});
observer.observe(terminalOutput);
</script>