【问题标题】:Count Up jQuery Timer计数 jQuery 计时器
【发布时间】:2012-10-05 15:42:10
【问题描述】:

我正在尝试使用这个 jQuery 计数脚本https://github.com/robcowie/jquery-stopwatch,但我想添加一个事件,如果计时器超过 2 分钟,#demo1 div 的 BG 颜色将变为红色

我已经在 jsfiddle 上添加了所有代码

http://jsfiddle.net/FeWrD/

【问题讨论】:

  • 我会尝试修改defaultFormatMilliseconds 函数。这个插件也应该实现一个tick 回调。

标签: jquery jquery-plugins stopwatch


【解决方案1】:
$(document).ready(function() {
  $('#demo1').stopwatch().bind('tick.stopwatch', function(e, elapsed){
  if (elapsed >= 120000) {
     $("#demo1").css("background", "red");
  } }).stopwatch('start')
}) 

来自文档

【讨论】:

    【解决方案2】:

    您需要将其绑定到 tick.stopwatch 事件。

    $(document).ready(function() {
    
        $('#demo1').stopwatch().bind('tick.stopwatch', function(e, elapsed) {
            if (elapsed <= 5000) {
                $("#demo1").css("background", "green");
            }
            else {
                $("#demo1").css("background", "orange");
            }
        }).stopwatch('start') ;
    });
    

    Check FIDDLE

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-04
      相关资源
      最近更新 更多