【问题标题】:On countdown end close modal倒计时结束关闭模式
【发布时间】:2020-06-29 08:33:19
【问题描述】:

我有一个倒数计时器,其工作原理如下

//countdown
const countdown = document.querySelector('.countdown');

// Set Launch Date (ms)
const launchDate = new Date('June 29, 2020 09:26:00').getTime();

// Update every second
const 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 calculation
const 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 result
countdown.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 reached
if (distance < 0) {
// Stop countdown
clearInterval(intvl);
// Style and output text
countdown.style.color = '#17a2b8';
countdown.innerHTML = 'Launched!';
}
}, 1000);

我有一个在此处关闭模式的当前函数。

$(".modalDialogload").css({"opacity":"0","pointer-events":"none"});
}, 2000);

我希望它在倒计时结束时运行,但我无法将其合并到 // 如果达到日期部分。

【问题讨论】:

    标签: javascript modal-dialog simplemodal


    【解决方案1】:

    如果我正确理解您的问题,您可以添加一些 js 来为您的模态添加新类。

         // 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;
        }
    

    【讨论】:

    • 谢谢,在原始函数中我使用了 $(".modalDialogload").css({"opacity":"0","pointer-events":"none"}); }, 2000);这创造了一个很好的褪色。用这种方法可以吗?
    • 是的,您所要做的就是将动画添加到 CSS 类中。以下是描述此方法的链接:tutorialspoint.com/css/css_animation_fade_out.htm
    猜你喜欢
    • 2015-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-06
    • 1970-01-01
    • 2020-11-30
    相关资源
    最近更新 更多