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.效果图: