I created a function with JavaScript, which is a countdown of the numbers on the screen that increases and decreases its size, however, the code is too large and I want to know how to do it in a more intelligent way without using many lines. Thank you
My code can be found here
var mudar5 = document.getElementById("cinco");
var mudar4 = document.getElementById("quatro");
var mudar3 = document.getElementById("tres");
var mudar2 = document.getElementById("dois");
var mudar1 = document.getElementById("um");
var mudarGo = document.getElementById("go");
mudar3.style.fontSize = "20px";
var fonteAtual = 1;
var minSize = 1;
var maxSize = 80;
var intervalTime = 10;
var intervalTimeDecrease = 2;
increaseSize();
//liga o cinco
function increaseSize() {
var interval = setInterval(function() {
fonteAtual++;
mudar3.style.fontSize = fonteAtual + "px";
if (fonteAtual === maxSize) {
clearInterval(interval);
decreaseSize();
}
}, intervalTime);
}
function decreaseSize() {
var interval = setInterval(function() {
fonteAtual--;
mudar3.style.fontSize = fonteAtual + "px";
if (fonteAtual === minSize) {
clearInterval(interval);
liga2();
}
}, intervalTimeDecrease);
}
//liga o quatro
function liga2() {
document.querySelector("#tres").style.display = "none";
document.querySelector("#dois").style.display = "block";
increasetwo();
}
function increasetwo() {
var interval = setInterval(function() {
fonteAtual++;
mudar2.style.fontSize = fonteAtual + "px";
if (fonteAtual === maxSize) {
clearInterval(interval);
decreasetwo();
}
}, intervalTime);
}
function decreasetwo() {
var interval = setInterval(function() {
fonteAtual--;
mudar2.style.fontSize = fonteAtual + "px";
if (fonteAtual === minSize) {
clearInterval(interval);
liga1();
}
}, intervalTimeDecrease);
}
//liga o 3
function liga1() {
document.querySelector("#dois").style.display = "none";
document.querySelector("#um").style.display = "block";
increaseone();
}
function increaseone() {
var interval = setInterval(function() {
fonteAtual++;
mudar1.style.fontSize = fonteAtual + "px";
if (fonteAtual === maxSize) {
clearInterval(interval);
decreaseone();
}
}, intervalTime);
}
function decreaseone() {
var interval = setInterval(function() {
fonteAtual--;
mudar1.style.fontSize = fonteAtual + "px";
if (fonteAtual === minSize) {
clearInterval(interval);
ligaGo();
}
}, intervalTimeDecrease);
}
//Liga o Go
function ligaGo() {
document.querySelector("#um").style.display = "none";
document.querySelector("#go").style.display = "block";
increaseGo();
}
function increaseGo() {
var interval = setInterval(function() {
fonteAtual++;
mudarGo.style.fontSize = fonteAtual + "px";
if (fonteAtual === maxSize) {
clearInterval(interval);
mudarGo.style.fontSize = 80 + "px";
}
}, intervalTime);
}
//liga o Um
function liga1() {
document.querySelector("#dois").style.display = "none";
document.querySelector("#um").style.display = "block";
increaseone();
}
function increaseone() {
var interval = setInterval(function() {
fonteAtual++;
mudar1.style.fontSize = fonteAtual + "px";
if (fonteAtual === maxSize) {
clearInterval(interval);
decreaseone();
}
}, intervalTime);
}
function decreaseone() {
var interval = setInterval(function() {
fonteAtual--;
mudar1.style.fontSize = fonteAtual + "px";
if (fonteAtual === minSize) {
clearInterval(interval);
ligaGo();
}
}, intervalTimeDecrease);
}
//Liga o Go
function ligaGo() {
document.querySelector("#um").style.display = "none";
document.querySelector("#go").style.display = "block";
increaseGo();
}
function increaseGo() {
var interval = setInterval(function() {
fonteAtual++;
mudarGo.style.fontSize = fonteAtual + "px";
if (fonteAtual === maxSize) {
clearInterval(interval);
mudarGo.style.fontSize = 80 + "px";
}
}, intervalTime);
}
#dois,
#um,
#go {
display: none;
font-size: 0px;
}
<body style="text-align: center; margin: 0 auto">
<div id="tres">3</div>
<div id="dois">2</div>
<div id="um">1</div>
<div id="go">GO!</div>
</body>