킹콩랩스

jquery 타이머 만들기

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>

<script>

function setTimer(selector,startValue,endValue,durationTime){

    $(selector).animate(

        {

            to:startValue,

            from:endValue

        },

        {

            duration:durationTime,

            step:function(idx){

                $(this).text(Math.floor(idx));

            }

        }

    );

}

 

$(function(){

    setTimer(".timer1",0,500,1000);

    setTimer(".timer2",0,5000,2000);

    setTimer(".timer3",0,50000,3000);

    setTimer(".timer4",0,500000,4000);

    setTimer(".timer5",0,5000000,5000);

 

    // 선택자,시작값,끝값,지연시간

});

</script>

<div class='timer1'></div>

<div class='timer2'></div>

<div class='timer3'></div>

<div class='timer4'></div>

<div class='timer5'></div>

 

 

animate함수로 간단하게 구현이 가능 합니다.

댓글 2개

잘 활용해보겠습니다.
댓글을 작성하시려면 로그인이 필요합니다.

개발자팁

5,404건

개발과 관련된 유용한 정보를 공유하세요. 질문은 QA에서 해주시기 바랍니다.

+
분류 제목 글쓴이 날짜 조회
기타 24-12-30 조회 2,020
MySQL 24-12-14 조회 1,862
기타 24-12-14 조회 2,032
JavaScript 24-12-13 조회 2,164
JavaScript 24-12-13 조회 1,672
PHP 24-12-13 조회 2,142
PHP 24-11-26 조회 4,574
기타 24-11-14 조회 2,493
기타 24-10-30 조회 2,760
PHP 24-10-11 조회 2,268
JavaScript 24-10-10 조회 1,337
JavaScript 24-09-26 조회 1,884
24-09-25 조회 2,507
JavaScript 24-09-07 조회 2,133
24-09-11 조회 1,572
24-09-19 조회 4,268
24-09-10 조회 4,356
24-08-19 조회 2,954
24-10-03 조회 1,826
24-08-07 조회 1,312
24-07-23 조회 2,000
24-07-08 조회 1,584
24-06-27 조회 1,490
PHP 24-08-23 조회 1,693
PHP 24-07-31 조회 1,444
OS 24-07-22 조회 2,418
기타 24-07-22 조회 1,279
기타 24-07-12 조회 1,489
기타 24-07-02 조회 1,705
기타 24-07-02 조회 1,168