2013-01-04 110 views
0

我得到了mootools的倒计时here,但它看起来像没有工作
我得到了36(this.timer = new PeriodicalExecuter(this.update.bind(this), (this.options.frequency || 1000)/1000);Mootools的计数器倒计时不行

PeriodicalExecuter似乎未列入mootools的在CountDown.js线一条错误消息Uncaught ReferenceError: PeriodicalExecuter is not defined 。希望有人拥有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版本与兼容性

回答

1

您可以更改类代码以使用标准m编制方法。

它看起来像.registerCallback只是一个函数,启动计时器,即。 setInterval。 显然.stop停止计时器,即。 clearInterval
PeriodicalExecuter类似乎做的唯一的事情是每次将实例化给它的参数传递给setInterval调用。

这是对足够的信息来实现它自己:)