Home >Web Front-end >JS Tutorial >js pure numbers one by one stop display effect implementation code_javascript skills

js pure numbers one by one stop display effect implementation code_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:10:341474browse

JS pure numbers one by one stop display effect implementation code

function showScore($ele, num, secand, pause){ //second 按照秒数,动画运行多少秒
        if (!secand) { secand = 2;}
        if (!pause) { pause = 20;}

        var len = String(num).length;

        var temnum, times = 0 , stepTimes, max ;
        var numArr = String(num).split("");


        function getRandom(n){
          var num = Math.floor(Math.random()*(Math.pow(10, n)-1 - Math.pow(10, n-1))+Math.pow(10, n-1));

          if (String(num).length !== n) {num = getRandom(n);}

          return num;
        }

        function setValue(num, pause, secand){//second 运行多少秒后停止
          var len = String(num).length, j=0;

          if (!stepTimes) {
            max = Math.ceil(secand*1000/len);
            stepTimes = Math.ceil(max/pause);
          }
          
          temnum = "";
          setTimeout(function(){
            for (var i = 1; i <= len; i++) {
              if (times >= stepTimes*i) {
                j++;
                temnum += numArr[i-1]+"";
              }else{
                break;
              }
            };

            if (j < len) {
              $ele.html(temnum+""+getRandom(len-j));
            }else{
              $ele.html(temnum);
            }
            
            
            if (times >= max || j >= len) {return;};

            setValue(num, pause, secand);
            times++;
            
          }, pause);


        }

        setValue(num, pause, secand);

      }

showScore($(".num"), 2344, 1.5, 10);

The effect of pure numbers is to stop displaying the effect one by one. For example, this number keeps changing. The first digit is determined first, then the second digit is determined, and then the third digit is determined. Because the project was abandoned after a few days of use, I saved it.

The above implementation code of js pure numbers one by one stop display effect is all the content shared by the editor. I hope it can give you a reference, and I also hope you will support Script Home.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn