#javascript #countdownjs.js
#javascript #countdownjs.js
Вопрос:
У меня есть веб-сайт в процессе разработки, но он еще не готов.У меня есть страница приветствия, где я хочу отобразить таймер обратного отсчета, пока сайт не будет готов.
Я использую 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 дня», независимо от того, какая дата!!
Комментарии:
1. попробуйте это без какого-либо плагина codepen.io/SitePoint/pen/MwNPVq
2. спасибо, я нашел проблему в js. по какой-то причине у меня была эта строка «thisEl.find(«.days»).text(24);» я просто изменил 24 на переменную days и все заработало!!!
Ответ №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'));
});
});