2016-12-05 46 views
-2

我正在使用下面的函数从0到PHP代码返回的值进行计数。计数小时和秒从0到指定值HH:mm

$('.count_start').each(function() { 
 
    var $this = $(this); 
 
    jQuery({ Counter: 0 }).animate({ Counter: $this.text() }, { 
 
    duration: 5000, 
 
    easing: 'swing', 
 
    step: function() { 
 
    $this.text(Math.ceil(this.Counter)); 
 
    } 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<div class="count_start"> 
 
    50 
 
</div>

但现在我想用相同或相似的函数来计算时间,但是时间exprressed以以下格式HH:MM(也可能是如11110:15或98: 55)。 HH的值可以大于两位数字 - 只保留分隔符“:”。

任何人都可以帮助功能发展?

回答

0

我试图实现分割功能,但我不知道如果我下面corrrect方式:

function countingdecimal() { 
    $('.countdecimal_start').each(function() { 
     var $this = $(this); 
     var timesplited = $this.toString().split(":"); 
     jQuery({ Counter: 0 }).animate({ Counter: timesplited[0].text() }, { 
     duration: 5000, 
     easing: 'swing', 
     step: function() { 
     timesplited[0].text(timesplited[0].Counter.toFixed(2)); 
     } 
     }); 

    jQuery({ Counter: 0 }).animate({ Counter: timesplited[1].text() }, { 
     duration: 5000, 
     easing: 'swing', 
     step: function() { 
     timesplited[1].text(timesplited[1].Counter.toFixed(2)); 
     } 
     }); 
    }); 
    } 
相关问题