- 根据自己的需要来封装
效果
image.png
countdownpay(倒计时分钟,分标签,秒标签,毫秒标签,是否显示标签);
function countdownpay(time,minutes1,seconds2,second3,isshow) {
var maxtime = time * 60 * 1000;
timer = window.setInterval(function () {
if (maxtime >= 0) {
var minutes = Math.floor(maxtime / 60 / 1000);
var seconds = Math.floor(maxtime / 1000 % 60);
var ms = Math.floor(maxtime % 1000 / 100);
var m = String(ms).charAt(0);
$(minutes1).text(minutes);
$(seconds2).text(seconds);
$(second3).text(m);
maxtime -= 10;
} else {
if (maxtime < 0) {
window.clearInterval(timer);
$(isshow).show();
}
console.log('倒计时结束')
}
}, 10)
}
网友评论