javascript 질문 입니다.

javascript 질문 입니다.

QA

javascript 질문 입니다.

본문

안녕하세요.
숫자가 카운팅되는 자바스크립트 소스를 구해서 사용중입니다.

소숫점까지 표현되어야되는 부분이 있는데 소숫점표현이 안되더라구요;

조언을 부탁드리겠습니다.

 


<div class="arrival item">
     <p class="radi_tem"><img src="image/main/quick_icon3.png" alt=""></p>
     <p id="counter3"><b>23.4%</b></p>
     <p>열무디자인 콘텐츠 <br>평균 추가 도달률</p>
</div>
 
<script>
        $(document).scroll(function(){
            var f = true;
            if($(this).scrollTop() < 1400)    {  
                if(f == true){
                function numberCounter(target_frame, target_number) {
                    this.count = 0; this.diff = 0;
                    this.target_count = parseInt(target_number);
                    this.target_frame = document.getElementById(target_frame);
                    this.timer = null;
                    this.counter();
                };
                    numberCounter.prototype.counter = function() {
                        var self = this;
                        this.diff = this.target_count - this.count;
                    
                        if(this.diff > 0) {
                            self.count += Math.ceil(this.diff / 5);
                        }
                    
                        this.target_frame.innerHTML = this.count.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
                    
                        if(this.count < this.target_count) {
                            this.timer = setTimeout(function() { self.counter(); }, 20);
                        } else {
                            clearTimeout(this.timer);
                        }
                    };
                new numberCounter("counter3", 23); // 이부분을 23.4%로 표현하고자 합니다.
                new numberCounter("counter2", 487);
                new numberCounter("counter1", 147654);
    
                }
                f = false;
            }
        });
    </script>

이 질문에 댓글 쓰기 :

답변 2

 

 self.count += Math.ceil(this.diff / 5);

                      ceil() 을 빼고 해 보세요

this.target_count = parseFloat(target_number);

this.target_frame = document.getElementById(target_frame);

 

이 부분 수정한 후에..

new numberCounter("counter3", 23.4); 

해보세요.

답변을 작성하시기 전에 로그인 해주세요.
전체 2,337
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT