我最近實作了這個 jsfiddle 中顯示的計數器:https ://jsfiddle.net/Behseini/osqzL4ob/
HTML
<div id="users">Counter: <b counter="0">0</b></div>
JS
function update_users_count() {
$('#users b').animate({
counter: 260
}, {
duration: 6000,
easing: 'swing',
step: function(now) {
$(this).text(Math.ceil(now));
},
complete: update_users_count
});
};
update_users_count();
在元素檢查器中,看起來腳本在執行后會繼續回圈(該值突出顯示并不斷重繪 )。有沒有辦法阻止這種情況發生?
uj5u.com熱心網友回復:
當然,只需洗掉complete: update_users_count(它的作用是:在"complete"上遞回回圈相同的函式,盡管值在其最終狀態計數中保持不變)。
jsFiddle 演示
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/472640.html
標籤:javascript
