2013-01-04 81 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調用。

這是對足夠的信息來實現它自己:)