Advertisement
Guest User

smoothCount revision 20250312

a guest
Mar 12th, 2025
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.71 KB | Source Code | 0 0
  1.  
  2. viewbox=document.getElementsByTagName("pre")[0];
  3. var viewcount=new Object({});
  4. var countUp; // declare for scope
  5. var tanh_animation=0;
  6. viewcount.old=0;
  7. viewcount.displayed=0;
  8. viewcount.new=1000;
  9. function increaseViewCount() {
  10.     viewcount.displayed=Math.round( viewcount.old + (viewcount.new-viewcount.old)*Math.tanh(tanh_animation/10) );
  11.     tanh_animation++;
  12.     viewbox.innerHTML=viewcount.displayed;
  13.     if ( Math.abs(viewcount.displayed-viewcount.new) < 0.5 ) {
  14.         clearInterval(countUp);
  15.         viewbox.innerHTML=viewcount.new;
  16.         viewcount.old=viewcount.new; // remember for next time
  17.         tanh_animation=0; // reset
  18.     };
  19. };
  20.  
  21. function countTo(number){
  22. viewcount.new=number;
  23. countUp=setInterval(increaseViewCount,50);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement