Last active
October 9, 2022 11:05
-
-
Save ArtemSites/6c1b654f2a38990ef7297e06dd3e32e0 to your computer and use it in GitHub Desktop.
Счетчик - таймер с выводом на экран | Counter - timer with display
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
initTimer(0, sectionStats3End, 2000, sectionStats3, '', ' лет'); | |
function initTimer(start, end, duration, objTarget, prefix = false, postfix = false) { | |
timer(); | |
function timer() { | |
let interval = Math.round(duration / Math.abs(start-end)); | |
let timerName = setInterval(function() { | |
if (start>end) { | |
if (start <= end) { | |
clearInterval(timerName); | |
} | |
objTarget.text(newText(start,prefix,postfix)); | |
start--; | |
} else { | |
if (start >= end) { | |
clearInterval(timerName); | |
} | |
objTarget.text(newText(start,prefix,postfix)); | |
start++; | |
} | |
}, interval); | |
} | |
function newText(newText,prefix,postfix) { | |
if (prefix) { | |
newText=prefix+newText; | |
} | |
if (postfix) { | |
newText=newText+postfix; | |
} | |
return newText; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment