[{{mminutes}}:{{sseconds}}] X
Пользователь приглашает вас присоединиться к открытой игре игре с друзьями .
[JS] simple-timer
(0)       Используют 6 человек

Комментарии

Ни одного комментария.
Написать тут
Описание:
простой таймер на JS
Автор:
CaffeeLatte
Создан:
3 июня 2017 в 22:34
Публичный:
Нет
Тип словаря:
Слова
Текст для игры будет составляться из слов, перемешанных в случайном порядке.
Содержание:
var time = 3,
fps = 60;
var Timer = function(obj){
this.time = obj.time;
this.fps = obj.fps;
this.onEnd = obj.onEnd || null;
this.onStart = obj.onStart || null;
this.onTick = obj.onTick || null;
this.intervalID = null;
this.start = () => {
this.interval = setInterval(this.update, 1000 / this.fps);
this.onStart ? this.onStart() : void 0;
return this;
};
this.stop = () => {
clearInterval(this.interval);
this.onEnd ? this.onEnd() : void 0;
};
this.update = () => {
this.time > 0 ? this.time -= 1/this.fps : this.stop();
this.onTick ? this.onTick() : void 0;
return this.get();
}
this.get = (par) => {
switch(par) {
case undefined:
return this.time;
break;
case "dig":
return Math.ceil(this.time);
break;
case "end":
return this.onEnd();
break;
}
}
}
var timer1 = new Timer({
time: time,
fps: fps,
onTick: tick,
onEnd: endTimer,
onStart: onTimerStart
});
function onTimerStart(){
console.log("timer started");
}
function endTimer(){
console.log("timer ended");
}
timer1.start()
requestAnimationFrame(tick);
function tick(){
id("output").innerHTML = timer1.get("dig");
id("slider").style.width = timer1.get()/time *100 + "%";
}
function id(id){
return document.getElementById(id);
}

Связаться
Выделить
Выделите фрагменты страницы, относящиеся к вашему сообщению
Скрыть сведения
Скрыть всю личную информацию
Отмена