pti*_*rs9 1 javascript window timer settimeout
我试图最终让这个代码工作:
function Timer(callback, delay) {
var timerId, start, remaining = delay;
this.pause = function() {
window.clearTimeout(timerId);
remaining -= new Date() - start;
};
this.resume = function() {
start = new Date();
timerId = window.setTimeout(callback, remaining);
};
this.resume();
}
var timer;
function onEvent(){
timer = new Timer(anotherEvent(), 5000);
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用,所以我简化它以查看可能存在的问题,并将其归结为:
var timer;
function event(){
timer = window.setTimeout(anotherEvent(), 5000);
}
Run Code Online (Sandbox Code Playgroud)
它所做的只是另一个事件().
有任何想法吗?
| 归档时间: |
|
| 查看次数: |
398 次 |
| 最近记录: |