-
Notifications
You must be signed in to change notification settings - Fork 0
/
show.js
32 lines (32 loc) · 1004 Bytes
/
show.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
import string from './displayText.js';
const upper = document.querySelector('.upperPart');
const pikachuStyle = document.querySelector(".Pikachu-style");
const normalButton = document.querySelector('.normalSpeed');
const stopButton = document.querySelector('.stop');
const fastSpeed = document.querySelector('.fastSpeed');
let n = 1;
function setTime(){
if(n <= string.length){
let content = string.substring(0,n);
upper.innerText = content;
pikachuStyle.innerHTML = content;
upper.scrollTop = upper.scrollHeight;
n += 1
}else{
for(let i = 0;i<=intervalId;i++){
clearInterval(i);
}
}
}
let intervalId = setInterval(setTime,30);
normalButton.onclick = () => {
intervalId = setInterval(setTime,30);
}
stopButton.onclick = () => {
for(let i = 0;i<=intervalId;i++){
clearInterval(i);
}
}
fastSpeed.onclick = () => {
intervalId = setInterval(setTime,5);
}