@matros97

Не правельно работает счетчик отчета времени?

Доброе утро, я не селен в JS, нашел готовый скрипт и под себя его подогнал стили
вот код
$(function(){
    
    var note = $('#note'),
        ts = new Date(2017, 0, 1),
        newYear = true;
    
    if((new Date()) > ts){
        // The new year is here! Count towards something else.
        // Notice the *1000 at the end - time must be in milliseconds
        ts = (new Date()).getTime() + 30*24*60*60*1000;
        newYear = false;
    }
        
    $('#countdown').countdown({
        timestamp   : ts,
        callback    : function(days, hours, minutes, seconds){
            
            var message = "";
            
            message += days + " day" + ( days==1 ? '':'s' ) + ", ";
            message += hours + " hour" + ( hours==1 ? '':'s' ) + ", ";
            message += minutes + " minute" + ( minutes==1 ? '':'s' ) + " <br />";
            
            if(newYear){
                message += "left until the new year!";
            }
            else {
                message += "left to 10 days from now!";
            }
            
            note.html(message);
        }
    });
    
});


1) Подскажет почему скрипт не считает ?
2) Подскажите где мне задать время до нового года, что он отчитовал время до НГ, потом я задам время до рождества
Вот ссылка на сайт
  • Вопрос задан
  • 158 просмотров
Пригласить эксперта
Ответы на вопрос 1
@SOKR
var nYrCo = (
function (){
	//ts - timer stop, newYear -flag  if it`s true that says , The new year is here
	var ts = new Date(2018, 0, 1),
	 now  = new Date(),
	 tshs=ts.toString().split(" "),
	 tds = now.toString().split(" "),
	 tsm=tshs[4].split(":"),
	 ths = tds[4].split(":");
	newYear = false,
	 countdown = ({
			timestamp : ts,
			
			callback  : function(days, hours, minutes, seconds){
				if(ts.getTime()-now.getTime()<0){
			// The new year is here! Count towards something else.
			// Notice the *1000 at the end - time must be in milliseconds
			 ts = (new Date()).getTime() + 30*24*60*60*1000;
			newYear = true;
		
			}
            var message = " ";
			
			message += days + " day" + ( days==1 ? '':'s' ) + ", ";
            message += hours + " hour" + ( hours==1 ? '':'s' ) + ", ";
            message += minutes + " minute" + ( minutes==1 ? '':'s' ) ;
			 if(newYear){
                message = " Congratulate! The new year has come! ";
            }
            else {
                message += " later, will come New Year!";
            }
            return message
			}(31-tds[2],24-tsm[0],60-tsm[1])
			 
			
	});
	
	
	
		
		
		
	return countdown
}
);
nYrCo();
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы