我在这里有一个 mootools 倒计时,但它看起来不起作用
我Uncaught ReferenceError: PeriodicalExecuter is not defined
在 CountDown.js 第 36 行 ( this.timer = new PeriodicalExecuter(this.update.bind(this), (this.options.frequency || 1000) / 1000);
) 中收到一条错误消息
该类PeriodicalExecuter
似乎不包含在 mootools 中。希望有人有代码PeriodicalExecuter
或知道我在哪里可以找到它。
该类PeriodicalExecuter
至少应包括功能stop()
和registerCallback()
这是CountDown.js的代码供您参考
/*
---
script: CountDown.js
license: MIT-style license.
description: CountDown - a mootools countdown implementation.
copyright: Copyright (c) 2008 Thierry Bela
authors: [Thierry Bela]
requires:
core:1.2.3:
- Events
- Options
provides: [CountDown]
...
*/
var CountDown = new Class({
/*
options: {
onChange: $empty,
onComplete: $empty,
date: null,
frequency: 1000 //define the update frequency (in ms), default to 1000
},
*/
Implements: [Options, Events],
initialize: function (options) {
this.setOptions(options);
if(!this.options.date instanceof Date) this.options.date = new Date(this.options.date);
this.timer = new PeriodicalExecuter(this.update.bind(this), (this.options.frequency || 1000) / 1000);
},
stop: function () {
this.timer.stop();
return this
},
start: function () {
this.timer.registerCallback();
return this
},
update: function () {
var millis = Math.max(0, this.options.date.getTime() - new Date().getTime()),
time = Math.floor(millis / 1000),
stop = time == 0,
countdown = {
days: Math.floor(time / (60 * 60 * 24)),
time: time,
millis: millis
};
time %= (60 * 60 * 24);
countdown.hours = Math.floor(time / (60 * 60));
time %= (60 * 60);
countdown.minutes = Math.floor(time / 60);
countdown.second = time % 60;
this.fireEvent('onChange', countdown);
if(stop) {
this.timer.stop();
this.fireEvent('onComplete');
}
}
});
编辑
我正在使用兼容的 Mootools 1.4.5 版