无编辑摘要 |
无编辑摘要 标签:已被回退 |
||
第1行: | 第1行: | ||
// 引入jQuery计时器插件[6](@ref) | // 引入jQuery计时器插件[6](@ref) | ||
mw.loader.load('//cdn.jsdelivr.net/npm/jquery-countdown@2.2.0/dist/jquery.countdown.min.js'); | mw.loader.load('//cdn.jsdelivr.net/npm/jquery-countdown@2.2.0/dist/jquery.countdown.min.js'); | ||
function startTimer(duration, display) { | |||
var timer = duration, days, hours, minutes, seconds; | |||
setInterval(function() { | |||
days = Math.floor(timer / (60 * 60 * 24)); | |||
hours = Math.floor((timer % (60 * 60 * 24)) / (60 * 60)); | |||
minutes = Math.floor((timer % (60 * 60)) / 60); | |||
seconds = Math.floor(timer % 60); | |||
display.textContent = days + "天 " + hours + ":" + minutes + ":" + seconds; | |||
if (--timer < 0) timer = duration; | |||
}, 1000); | |||
} | |||
// 初始化30天倒计时 | |||
window.onload = function() { | |||
var thirtyDays = 30 * 24 * 60 * 60, | |||
display = document.querySelector('#timer'); | |||
startTimer(thirtyDays, display); | |||
}; |