我想在一个计数器后添加一个美元符号,如果其中一个div有一个类.dollar,但是它将它放在所有.counter div中。
$('.counter').each(function() {
var $this = $(this),
countTo = $this.attr('data-count');
$({
countNum: $this.text()
}).animate({
countNum: countTo
}, {
duration: 2000,
easing: 'linear',
step: function() {
if ($('.counter').hasClass('dollar')) {
$this.text(commaSeparateNumber(Math.floor(this.countNum) + '$'));
} else {
$this.text(commaSeparateNumber(Math.floor(this.countNum)));
}
},
complete: function() {
$this.text(commaSeparateNumber(this.countNum));
}
});
});