Javascript 在flipclock.js倒计时中,隐藏时钟,即使在浏览器刷新后也是如此

Javascript 在flipclock.js倒计时中,隐藏时钟,即使在浏览器刷新后也是如此,javascript,Javascript,提前谢谢 我目前有一个dev-PHP网页,它在页面加载时从其web服务器获得“实时”时间。页面中有一个flipclockjs倒计时,它使用服务器的时间作为“当前日期”,而不是“未来日期”,以确定倒计时何时结束 到目前为止一切都很好。无论是在英国、美国还是澳大利亚浏览网页,倒计时都将在全球格林尼治标准时间的同一时间结束 我的问题是倒计时到零时。我可以使用flipclock的stop:函数回调,将一个全新的css类应用于包含时钟的div,并在我的样式表中有一个与该新类匹配的样式,该样式隐藏时钟-例如

提前谢谢

我目前有一个dev-PHP网页,它在页面加载时从其web服务器获得“实时”时间。页面中有一个flipclockjs倒计时,它使用服务器的时间作为“当前日期”,而不是“未来日期”,以确定倒计时何时结束

到目前为止一切都很好。无论是在英国、美国还是澳大利亚浏览网页,倒计时都将在全球格林尼治标准时间的同一时间结束

我的问题是倒计时到零时。我可以使用flipclock的stop:函数回调,将一个全新的css类应用于包含时钟的div,并在我的样式表中有一个与该新类匹配的样式,该样式隐藏时钟-例如可见性:隐藏

但是如果有人在倒计时结束后访问页面的URL,或者在倒计时结束后刷新浏览器页面,我的问题就会出现。每个实例似乎都绕过了时钟停止的实际操作,因此类不会被应用,时钟也不会被隐藏

我只剩下一个可见的时钟,上面显示着看似随机的负数

var clock;
    $(document).ready(function() {

    // Grab the current date
    var currentDate = new Date('<? print date("F d, Y H:i:s", time())?>');

    // Set some date in the future.
    var futureDate  = new Date("November 09, 2017 14:20:00");

    // Calculate the difference in seconds between the future and current date
    var diff = futureDate.getTime() / 1000 - currentDate.getTime() / 1000;

    // Instantiate a coutdown FlipClock
    clock = $('.clock').FlipClock(diff, {
    clockFace: 'HourCounter',
    countdown: true,

        callbacks: {
                stop: function() {
                $('.clock').addClass("hideCountdown");
                $('.message').html('Our First Offer Has Ended!');
                                }
                            }

        });
    });
var时钟;
$(文档).ready(函数(){
//抓取当前日期
var currentDate=新日期(“”);
//为将来定个日期。
var futureDate=新日期(“2017年11月9日14:20:00”);
//计算未来日期和当前日期之间的秒差
var diff=futureDate.getTime()/1000-currentDate.getTime()/1000;
//实例化一个coutdown FlipClock
时钟=$('.clock')。翻转时钟(不同{
钟面:“小时计数器”,
倒计时:没错,
回调:{
停止:函数(){
$('.clock').addClass(“hideCountdown”);
$('.message').html('我们的第一次报价已结束!');
}
}
});
});

只要添加一个检查,如果
不一致,那么添加检查,如果时间在过去。。。。如果是,请不要运行它。
var clock, clock2;
$(document).ready(function () {
    // Grab the current date
    var currentDate = new Date();
    // Set some date in the future.
    var futureDate = new Date(); 
    futureDate.setSeconds(futureDate.getSeconds() - 10);
    // Calculate the difference in seconds between the future and current date
    var diff = futureDate.getTime() / 1000 - currentDate.getTime() / 1000;
    if (diff <= 0) {
    $('.message').html('Our First Offer Has Ended!');   
    } else {
      // Instantiate a coutdown FlipClock
        clock = $('.clock').FlipClock(diff, {
            clockFace: 'HourCounter',
            countdown: true,
            callbacks: {
            stop: function() {
                $('.clock').addClass("hideCountdown");
                $('.message').html('Our First Offer Has Ended!');
            }
            }
        });
    }    
});