- 정보공유
[JQUERY] 금액 카운팅 모션 다라라락 변화
<div class="calculator-group">
<select name="selectname1">
<option value="1" data-price="100">100<option>
<option value="2" data-price="200">200<option>
<option value="3" data-price="300">300<option>
</select>
<select name="selectname2">
<option value="11" data-price="1100">1100<option>
<option value="12" data-price="1200">1200<option>
<option value="13" data-price="1300">1300<option>
</select>
</div>
<div class="total-price"><span class="price">0</span>원</div>
function countEvent() {
let total_price = price = 0;
$('.calculator-group select').each(
function(){
price = $(this).children('option:selected').data('price');
if (price == null) {
price = 0;
}
total_price += parseInt(price);
}
);
let target = $('.total-price .price');
let now = 0;
let machine = setInterval(()=>{
now=now+1;
if(total_price <= now){now=total_price;}
target.html(now.toLocaleString());
if(now >= total_price){
clearInterval(machine);
}
now=now+1000;
},10);
}