慕田峪7331174
2022-10-21 14:32:56
我有一個倒數(shù)計時器,其工作原理如下//countdownconst countdown = document.querySelector('.countdown');// Set Launch Date (ms)const launchDate = new Date('June 29, 2020 09:26:00').getTime();// Update every secondconst intvl = setInterval(() => {// Get todays date and time (ms)const now = new Date().getTime();// Distance from now and the launch date (ms)const distance = launchDate - now;// Time calculationconst days = Math.floor(distance / (1000 * 60 * 60 * 24));const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));const mins = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));const seconds = Math.floor((distance % (1000 * 60)) / 1000);// Display resultcountdown.innerHTML = `<div>${days}<span>Days</span></div> <div>${hours}<span>Hours</span></div><div>${mins}<span>Minutes</span></div><div>${seconds}<span>Seconds</span></div>`;// If launch date is reachedif (distance < 0) {// Stop countdownclearInterval(intvl);// Style and output textcountdown.style.color = '#17a2b8';countdown.innerHTML = 'Launched!';}}, 1000);我有一個在此處關(guān)閉模式的當(dāng)前功能。$(".modalDialogload").css({"opacity":"0","pointer-events":"none"});}, 2000);我希望它在倒計時結(jié)束時運(yùn)行,但我無法將其合并到 // 如果達(dá)到日期部分。
1 回答

四季花海
TA貢獻(xiàn)1811條經(jīng)驗 獲得超5個贊
如果我正確理解您的問題,您可以添加一些 js 以將新類添加到您的模態(tài)中。
// If launch date is reached
if (distance < 0) {
// Stop countdown
clearInterval(intvl);
// Style and output text
countdown.style.color = '#17a2b8';
cou
ntdown.innerHTML = 'Launched!';
// Add this line
let modal = document.querySelector('.modalDialogload');
modal.classList.add('HideModalClass');
// End
}
.HideModalClass{
opacity: 0;
pointer-events:none;
display:none;
}
添加回答
舉報
0/150
提交
取消