-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
53 lines (52 loc) · 1.42 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<div>123123</div>
<button id="p">暂停</button>
<button id="r">恢复</button>
<button id="cl">更改为周期执行</button>
<button id="co">更改为一次性执行</button>
<script type="module">
import PausableTimer from "./dist/main.esm.js";
const pt = new PausableTimer({
// 运行模式,只限于'loop','once'
mode: "loop",
// 调用周期,毫秒
timer: 2000,
// 回调
callback: () => {
console.log("panda");
},
// 可选,是否开启调试,控制台会打印一些额外信息
debug: true,
});
// 暂停
pt.pause();
// 恢复
pt.resume();
// 改变运行模式,['loop'|'once'],第二个参数为可选,是否重新计时
pt.setMode("loop", true);
// 停止运行
pt.stop();
const mySetInterval = (callback, delay) => {
return new PausableTimer({
callback,
timer: delay,
mode: "loop",
});
};
mySetInterval(() => {
console.log("666");
}, 1000);
const myClearInterval = (t) => {
t.stop();
};
</script>
</body>
</html>