【问题标题】:How can I set the current tick count of a goog.Timer?如何设置 goog.Timer 的当前滴答计数?
【发布时间】:2012-08-05 00:32:50
【问题描述】:

我正在修改 goog.Timer 并阅读它的 API:http://closure-library.googlecode.com/svn/docs/class_goog_Timer.html

有没有办法设置当前时间或计时器的刻度?例如,我可以将定时器的当前时间设置为 5000 毫秒吗?

【问题讨论】:

    标签: google-closure google-closure-library


    【解决方案1】:

    goog.Timerwindow.setInterval 之上的抽象,它以设定的时间间隔重复调度goog.Timer.TICK 事件。可以使用第一个构造函数参数或方法setInterval() 指定间隔。

    这是一个每 5 秒递增一次滴答计数器的示例。

    var tickCount = 0;
    
    /**
     * Tick callback.
     */
    var tickCounter = function() {
      tickCount++;
    };
    
    var timer = new goog.Timer(5000);
    timer.start();
    goog.events.listen(timer, goog.Timer.TICK, tickCounter);
    

    【讨论】:

    • 谢谢,我这样做了,并将刻度数存储在另一个包装类中。
    猜你喜欢
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多