Я внедрил запятую для roundNum
, из которой я показываю общее число, которое перемещается;Проблемы с добавлением запятых к номерам
$.fn.digits = function(){
return this.each(function(){
$(this).text($(this).text().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"));
});
};
$('.total').text(roundNum).digits();
Однако я не могу сделать то же самое с фактическим счетчиком.
$.fn.countTo = function(options) {
// merge the default plugin settings with the custom options
options = $.extend({}, $.fn.countTo.defaults, options || {});
// how many times to update the value, and how much to increment the value on each update
var loops = Math.ceil(options.speed/options.refreshInterval),
increment = (options.to - options.from)/loops;
return $(this).each(function() {
var _this = this,
loopCount = 0,
value = options.from,
interval = setInterval(updateTimer, options.refreshInterval);
function updateTimer() {
value += increment;
loopCount++;
$(_this).html(value.toFixed(options.decimals));
if (typeof(options.onUpdate) == 'function') {
options.onUpdate.call(_this, value);
}
if (loopCount >= loops) {
clearInterval(interval);
value = options.to;
if (typeof(options.onComplete) == 'function') {
options.onComplete.call(_this, value);
}
}
}
});
};
$.fn.countTo.defaults = {
from: 0, // the number the element should start at
to: 100, // the number the element should end at
speed: 1000, // how long it should take to count between the target numbers
refreshInterval: 100, // how often the element should be updated
decimals: 0, // the number of decimal places to show
onUpdate: null, // callback method for every time the element is updated,
onComplete: null, // callback method for when the element finishes updating
};
$('.timer').countTo({
from: 0,
to: roundNum,
speed: speed,
refreshInterval: 600,
onComplete: function() {
console.debug(this);
}
});
Этим вопрос уже ответил на эту тему: http://stackoverflow.com/questions/2901102/how-to-print-a-number-with-commas-as-thousands-separators-in-javascript –
@SteveKline, если вы, пожалуйста, прочитаете вопрос, я уже есть функция, однако у меня возникают проблемы с ее внедрением в другую. –
Справа, извините, я пропустил эту часть. Извиняюсь. –