2017-06-28 12 views
-2

最後に2桁の数字が表示されないのはなぜですか? Javascript output is in white and the desired numbers are in black aboveJS関数カウンタが正しい数値を出力しない

enter image description here

のJsコード:

$('.count').each(function() { 
    $(this).prop('Counter', 0).animate({ 
     Counter: $(this).text() 
    }, { 
     duration: 1000, 
     easing: 'swing', 
     step: function (now) { 
      $(this).text(now); 
     } 
    }); 
}); 
+1

を、外部リンクを投稿しないでください。少なくとも、それは不便です。私にとって、私はプロキシサーバーによってドロップボックスがブロックされており、あなたを助けることができません。 –

+0

何の末尾に2桁の数字がありませんか? –

+0

まあ、3.740の場合は1桁、4.400の場合は2桁 – Lukas

答えて

1

あなたは(toFixed(N)で)表示されますどのくらいの数字を選択する後続のゼロを維持する必要があります。以下の例では3進:

$(document).ready(function(){ 
$('.count').each(function() { 

    if($(this).text() % 1 != 0){ 

    $(this).prop('Counter', 0).animate({ 
     Counter: $(this).text() 
     }, { 
      duration: 1000, 
      easing: 'swing', 
      step: function (now) { 
       $(this).text(now.toFixed(3)); 
      } 
     }); 

    }else{ 

    $(this).prop('Counter', 0).animate({ 
     Counter: $(this).text() 
     }, { 
      duration: 1000, 
      easing: 'swing', 
      step: function (now) { 
       $(this).text(now.toFixed(0)); 
      } 
     }); 

    } 

}); 
}); 

https://jsfiddle.net/o2gxgz9r/9319/

+0

他の数字は間違っています:https://www.dropbox.com/s/tk8u41hc0qo4czt/Screenshot%202017-06-28%2013.18.46.png?dl=0 – Lukas

+1

答えを更新します。私は値が小数であるかどうかをチェックし、各ケースごとに異なるカウンターを使用します。 – Andrea

+0

ありがとうございました! – Lukas

-1

$(this).text(valueOf(now)); 

の代わりに使用して、それを解決:あなたはここで、この画像をアップロードする必要が

$(this).text(now); 
関連する問題