【问题标题】:jquery.final-countdown.js - need help configuring itjquery.final-countdown.js - 需要帮助配置它
【发布时间】:2015-05-05 00:50:51
【问题描述】:

这里有配置(以及如何使用)此插件的说明: http://www.jqueryscript.net/time-clock/Modern-Circular-jQuery-Countdown-Timer-Plugin-Final-Countdown.html

初始化倒数计时器并在javascript中设置开始时间、结束时间和当前时间。

$('.countdown').final_countdown({ 开始:'1362139200', 结束:'1388461320', 现在:'1387461319' });

首先,我不知道这些数字是什么意思……甚至没有解释。我推断它们的意思是秒。

所以我这样设置我的代码:

    $('.countdown').final_countdown({
    'start':    0, /* ((((Jan + Feb + 3 days) * number of hours in a day) * number of minutes in an hour) * number of seconds in a minute) = total seconds */
    'end':      ((((31+28+31+2)*24)*60)*60), /* started at 9:25 pm on March 03 */
    'now':      ((((31+28+3)*24)*60)*60),
    seconds: {
        borderColor: '#8ef58e',
        borderWidth: '9'
    },
    minutes: {
        borderColor: '#ff8d72',
        borderWidth: '9'
    },
    hours: {
        borderColor: '#69ccff',
        borderWidth: '9'
    },
    days: {
        borderColor: '#ffd35c',
        borderWidth: '9'
    }
});

问题是每次加载页面时,它显示的都是相同的 29 天。该脚本未获取当前时间/日期并与未来的另一个时间/日期进行比较。

所以现在看起来还不错(29 天),但几天后有人会加载这个页面,它会完全关闭。

您可以在此处查看脚本(和问题): http://www.3rd-dimension.co

非常感谢您对此提供的任何帮助。

【问题讨论】:

    标签: javascript jquery jquery-plugins countdown jquery-countdown


    【解决方案1】:

    问题在于您的“now”值是一个固定值(例如'now': ((((31+28+3)*24)*60)*60),)。

    相反,您应该使用 JavaScript 的原生 new Date() 动态获取您的 'now' 值,如下所示:

    // We will get the "now" value from this variable
    var today = new Date();
    
    // My target date is this month 30th 9.25pm
    var target = new Date(today);
    target.setDate(30);
    target.setHours(21,25,0,0);;
    
    // Countdown start from yesterday
    var yesterday = new Date(today);
    yesterday.setDate(today.getDate() - 1);
    yesterday.setHours(0,0,0,0);;
    
    $('.countdown').final_countdown({
        'start': yesterday.getTime() / 1000,
            'end': target.getTime() / 1000,
            'now': today.getTime() / 1000,
        seconds: {
            borderColor: '#8ef58e',
            borderWidth: '9'
        },
        minutes: {
            borderColor: '#ff8d72',
            borderWidth: '9'
        },
        hours: {
            borderColor: '#69ccff',
            borderWidth: '9'
        },
        days: {
            borderColor: '#ffd35c',
            borderWidth: '9'
        }
    });
    

    请参考小提琴的工作示例: http://jsfiddle.net/zeskysee/v0hc6cfj/11/

    希望得到帮助:)

    【讨论】:

      【解决方案2】:
      <script type="text/javascript">
              $('document').ready(function () { var end = Math.floor((new Date("02/11/2018")).getTime() / 1000);
                  var start = Math.floor((new Date("01/23/2018")).getTime() / 1000);
                  var now = Math.floor((new Date).getTime() / 1000);
                  $('.countdown').final_countdown({
                      'start': start,
                      'end': end,
                      'now': now
      
                  });
            });
      

      【讨论】:

        猜你喜欢
        • 2011-07-23
        • 1970-01-01
        • 2015-09-06
        • 2020-07-09
        • 2021-10-18
        • 1970-01-01
        • 1970-01-01
        • 2018-04-12
        • 1970-01-01
        相关资源
        最近更新 更多