js純數字逐一停止顯示效果的實現代碼_javascript技巧

來源:互聯網
上載者:User

js純數字逐一停止顯示效果的實現代碼

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);

效果純數字逐一停止顯示效果,比如這個個數字不停的變化,第一位先定下來,第二位再確定,然後第三位再確定下來。因為項目用了幾天廢棄,所以存下檔。

以上這篇js純數字逐一停止顯示效果的實現代碼就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援雲棲社區。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.