javascript setTimeout定时器步长函数
javascript setTimeout timer step function
我正在尝试使用自定义计时器创建一个函数,它将推进我正在运行的动画的一帧。我有计时器能够暂停和恢复的时刻,但我还没有能够找出一种方法来得到一个步骤函数的工作。我的动画超时延迟设置为25毫秒。
下面是我正在处理的:
Delay = 25
//This function is a custom timer that tracks the start time of a timeout and calculates the remaining time
// in order to resume at the appropriate frame of animation.
function Timer(callback, delay) {
var timerId, start, remaining = delay;
this.pause = function() {
window.clearTimeout(timerId);
remaining -= new Date() - start;
animate = false;
};
this.resume = function() {
start = new Date();
window.clearTimeout(timerId);
timerId = window.setTimeout(callback, remaining);
animate = true;
};
this.resume();
}
我很感激任何人能给我的任何帮助,我还在学习,从来没有很好的定时器或定时器事件。
我设法解决了我自己的问题!这是我最终得到的结果。
//This function is a custom timer that tracks the start time of a timeout and calculates the remaining time
// in order to resume at the appropriate frame of animation.
function Timer(callback, delay){
var timerId, start, remaining = delay;
this.pause = function(){
window.clearTimeout(timerId);
remaining -= new Date() - start;
animate = false;
};
this.resume = function(){
start = new Date();
window.clearTimeout(timerId);
timerId = window.setTimeout(callback, remaining);
animate = true;
};
this.step = function(){
timer.pause();
animate = false;
advanceAnimation(true);
};
this.resume();
}
您可以使用Interval来代替Timeout,它将像步骤一样重复,直到clearInterval()被调用。
相关文章:
- 如何在php/javascript中制作定时器和警报
- 双倒计时定时器
- 一个定时器事件会在多大程度上减慢我在JavaScript中的代码
- 如何使这个JavaScript定时器正常工作
- 定时器输出保存
- 在两次java定时器循环后重定向访问者
- 如何解决jquery自定义定时器问题
- 如何为PHP/JS游戏制作倒计时/定时器
- vue.js使用定时器自动重新加载/刷新数据
- 如何让javascript定时器在不查看选项卡/窗口时停止
- Javascript定时器函数
- Javascript定时器切换函数
- 使用动态参数禁用setInterval函数中的定时器
- 为什么clearInterval()函数不停止javascript定时器
- javascript setTimeout定时器步长函数
- 使用`?`在JavaScript定时器函数返回中
- 如何用定时器协调2个函数->javascript
- 如何清除定时器在setInterval函数与点击触发
- Javascript函数调用定时器不能正常工作
- 如何停止定时器与另一个函数javascript