我在这里找到了许多计数器的解决方案,从一个总数到另一个动画。
这是我现在正在使用的:
jQuery.fn.extend({
ts : function (from, to, time) {
var steps = 1,
self = this,
counter;
if (from - to > 0) {
steps = -1;
};
from -= steps;
function step() {
self.text(from += steps);
if ((steps < 0 && to >= from) || (steps > 0 && from >= to)) {
clearInterval(counter);
};
};
counter = setInterval(step, time || 5);
}
});
var total = $('.total').ts(56000,56941);
它运行良好,但是我想在总数中添加一个逗号,例如 56,941。这可能吗?
谢谢!