-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
57 lines (51 loc) · 1.28 KB
/
script.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
const start = document.querySelector("#start");
const scroll = document.querySelector("#scroll");
const pi = document.querySelector("#pi");
let doted, timeOuts;
const t = 5;
function startCalc(a, b) {
let c = a/b;
let d = Math.floor(c);
let e = a%b;
if (e<7) {
pi.innerText += d;
if (!doted) {
pi.innerText += ".";
doted = true;
}
e *= 10;
timeOuts = setTimeout(function() {
startCalc(e, 7)
}, t);
} else {
timeOuts = setTimeout(function() {
startCalc(e, 7)
}, t);
}
}
start.addEventListener("click", e => {
const state = e.target.innerText === "START";
if (state) {
e.target.innerText = "STOP";
pi.innerText = ""
clearTimeout(timeOuts);
doted = false;
startCalc(22, 7);
} else {
e.target.innerText = "START";
clearTimeout(timeOuts);
}
});
var interval;
scroll.addEventListener("click", e => {
if (interval) {
clearInterval(interval);
interval = null;
e.target.innerText = "START SCROLL";
return;
}
interval = setInterval(() => {
window.scrollTo(0,document.body.scrollHeight)
}, t);
e.target.innerText = "STOP SCROLL";
});