0
我希望在累積獎金數量上動畫自動增量,因爲我希望增量從4開始直到結束。由於我有工作的JavaScript,但這個JavaScript包含onclick,我不想onclick在JAVASCRIPT中顯示自動增加量
我們該怎麼做?
我的HTML:
<div class="ticker">
<div id="total-ticker" class="total-ticker"><span class="jackpot jackpot_num">2</span> <span class="jackpot jackpot-comm"> </span><span class="jackpot jackpot_num">5</span> <span class="jackpot jackpot_num">6</span> <span class="jackpot jackpot_num">2</span> <span class="jackpot jackpot-comm"> </span><span class="jackpot jackpot_num">3</span> <span class="jackpot jackpot_num">0</span> <span class="jackpot jackpot_num">7</span> <span class="jackpot jackpot-dot"> </span><span class="jackpot jackpot_num">9</span> <span class="jackpot jackpot_num">4</span> </div>
</div>
例子:
$2 5 6 2 3 0 7 9 4
的Javascript:
jQuery.fn.extend({
animateCount : function (from, to, time) {
var steps = 1,
self = this,
counter;
if (from - to > 0) {
steps = -1;
};
from -= steps;
function step() {
self.val(from += steps);
if ((steps < 0 && to >= from) || (steps > 0 && from >= to)) {
clearInterval(counter);
};
};
counter = setInterval(step, time || 100);
}
});
$('#runner').click(function() {
$('#count').animateCount(1,100);
})