js十分鍾倒計時


1.代碼:
 
html:
 
<div class="text_align_center" style="padding: 15px 0;">
    <span>支付剩余時間</span>
    <span id="timer" class="font-weight-bold font-20 text_color">10:00:9</span>
</div>
 
js:
 
//支付倒計時
let maxTime = 10 * 60; //定義十分鍾
let ms = 9; //毫秒
let step = -1; //減少量
 
 
function payCountDown() {
    if (maxTime > 0) {
        ms += step;
        if (ms < 0) {
            ms = 9;
        }
        let minutes = Math.floor(maxTime / 60) >= 10 ? Math.floor(maxTime / 60) : '0' + Math.floor(maxTime / 60);
        let seconds = Math.floor(maxTime % 60) >= 10 ? Math.floor(maxTime % 60) : '0' + Math.floor(maxTime % 60);
        // let ms = Math.floor(10 - maxTime * 10 % 10);
        let msg = minutes + ":" + seconds + ":" + ms;
        $('#timer').text(msg);
        maxTime -= 0.1;
        // maxTime = (maxTime * 10 -1) / 10;
    } else {
        $('#timer').text("00:00:0");
        clearInterval(timer);
    }
}
 
 
timer = setInterval("payCountDown()", 100);
 
 
2.效果圖:
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM