【问题标题】:How to fix countdown timer?如何修复倒数计时器?
【发布时间】:2019-03-27 09:37:00
【问题描述】:

我正在开发一个网站,但尚未准备好。我有一个欢迎页面,我想在其中显示倒数计时器,直到网站准备就绪。

我正在使用 countdown.js 插件。 这是我正在使用的脚本:

$(document).ready(function() {
"use strict";
$("#countdowncont").countdown({
    date: "30 april 2019 12:00:00", /** Enter new date here **/
    format: "on"
},
function() {
    // callback function
});
});

在日期范围内,无论日期是什么,我总是得到“24 天”!!

【问题讨论】:

  • 试试这个没有任何插件codepen.io/SitePoint/pen/MwNPVq
  • 感谢我在 js 中发现了问题。出于某种原因,我有这行 "thisEl.find(".days").text(24);"我刚刚将 24 更改为 days 变量,一切正常!!!

标签: javascript countdownjs.js


【解决方案1】:
  //create a count down timer with own vanilla JS

  function countDown(targetDate, targetMonth, targetYear) {
    var targetCountDown = targetMonth+ " " + targetDate+ " " + targetYear+ " " + "23:59:59";
    var targetCountDown = Date.parse(targetCountDown);
    var currntTime = Date.parse(new Date());
    var t = targetCountDown - currntTime;
    var seconds = Math.floor( (t/1000) % 60 );
    var minutes = Math.floor( (t/1000/60) % 60 );
    var hours = Math.floor( (t/(1000*60*60)) % 24 );
    var days = Math.floor( t/(1000*60*60*24) );
    console.log(t);
    if(t < 0) { return " 0:0:0 {Sorry Sir, Forgot your past, And go ahead!}" ; }
    return {
        'total': t,
        'days': days,
        'hours': hours,
        'minutes': minutes,
        'seconds': seconds
    };

}

console.log(countDown(01,01,2020)); // Format will be DD/MM/YYYY
Output :- {total: 24222070000, days: 280, hours: 8, minutes: 21, seconds: 10}

【讨论】:

    【解决方案2】:

    试试这个::

       $(document).ready(function () {
            "use strict";
            $('#countdowncont').countdown('2019/04/30', function (event) {
            $(this).html(event.strftime('%w weeks %d days %H:%M:%S'));
        });
        });
    

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 2012-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-10
      • 1970-01-01
      相关资源
      最近更新 更多