2016-09-17 2 views
0

증분 시작을 4에서 끝까지 원하는대로 잭팟 금액에 자동 증가를 적용하고 싶습니다. 내가 자바 스크립트를 가지고 있지만이 자바 스크립트는 onclick을 포함하고 나는 onclick하지 않기를 바란다.JAVASCRIPT의 자동 증분 금액 표시

우리는 어떻게 하는가?

MY HTML :

<div class="ticker"> 
    <div id="total-ticker" class="total-ticker"><span class="jackpot jackpot_num">2</span> <span class="jackpot jackpot-comm">&nbsp;</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">&nbsp;</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">&nbsp;</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 

자바 스크립트 :

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); 
}) 

답변

0

아주 간단한 ... 클릭 처리기에서 카운터 플러그인 초기화를 취할 때 초기화 페이지가 대신로드 됨

$(function(){// make sure dom is ready 
    $('#count').animateCount(1,100); 
});