仿【數字】無限上下滾動增加數值-計數器-仿直播人數統計
阿新 • • 發佈:2018-12-10
css:
.sdvm_num{! font-size: 14px;color:red;display:inline-block;vertical-align:middle;margin-left:8px;}
.sdvm_num i{width:70px;height:52px;display:inline-block;background:url(../images/number1.png) no-repeat;background-position:0 0;margin:0 5px;}
html:
<span class="sdvm_num"> <!-- <i style="background-position: 0px -312px;"></i> --> <i style="background-position: 0px 0px;"></i> <i style="background-position: 0px 0px;"></i> <i style="background-position: 0px 0px;"></i> <i style="background-position: 0px 0px;"></i> <i style="background-position: 0px 0px;"></i> <i style="background-position: 0px 0px;"></i> <i style="background-position: 0px 0px;"></i> </span>
js:
window.sum=500; setInterval(function(){ for (var i = 0; i < sum.toString().length; i++) { if (sum.toString().length<7) { sum='0'+sum; } } show_num1(sum) },2000); function show_num1(n) { sum=Number(sum)+3; var it = $(".sdvm_num i"); var len = String(n).length; for(var i = 0; i < len; i++) { // $('.sdvm_nums').hide(); if(it.length <= i) { $(".sdvm_num").append("<i></i>"); } var num = String(n).charAt(i); //根據數字圖片的高度設定相應的值 var y = -parseInt(num) * 52; var obj = $(".sdvm_num i").eq(i); obj.animate({ backgroundPosition: '(0 ' + String(y) + 'px)' }, 'slow', 'swing', function() {}); } // $("#cur_num").val(n); }
圖片:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAAIICAYAAADT45ixAAAACXBIWXMAAAsTAAALEwEAmpwYAAAI22lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxNDIgNzkuMTYwOTI0LCAyMDE3LzA3LzEzLTAxOjA2OjM5ICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnL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