Is there a way to create a gradient that remains static and masks out certain visible parts?
I want the countdown timer to darken as it nears the end. Currently, my gradient only reduces colors in between while keeping the left and right colors:
(function() {
function resetCountdown() {
window.requestAnimationFrame(function() {
document.getElementById("countdown-evolution").classList.remove("countdown-reset");
window.requestAnimationFrame(function() {
document.getElementById("countdown-evolution").classList.add("countdown-reset");
});
});
}
resetCountdown();
document.getElementById("countdown-evolution").addEventListener("transitionend", resetCountdown);
})();
/* Background */
#countdown-background {
height: 50px;
width: 100%;
box-sizing: border-box;
border: 1px solid #ebebeb;
background-color: #ffffff;
}
/* Fill */
#countdown-evolution {
height: 100%;
width: 100%;
transform-origin: left;
background: linear-gradient(to right, #6419cd, #3273fa);
}
/* Reset */
.countdown-reset {
transition: transform 15s linear;
transform: scaleX(0);
}
/* Reference */
.fixed-background {
height: 50px;
width: 100%;
box-sizing: border-box;
background: linear-gradient(to right, #6419cd, #3273fa);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8>
<title>Countdown</title>
</head>
<body>
<div id="countdown-background>
<div id="countdown-evolution></div>
</div>
<div class="fixed-background></div>
</body>
</html>
I have tried making countdown-background
a gradient and countdown-evolution
a solid color for the desired effect. However, this caused more issues than solutions as it changed the appearance of my countdown timer:
(function() {
function resetCountdown() {
window.requestAnimationFrame(function() {
document.getElementById("countdown-evolution").classList.remove("countdown-reset");
window.requestAnimationFrame(function() {
document.getElementById("countdown-evolution").classList.add("countdown-reset");
});
});
}
resetCountdown();
document.getElementById("countdown-evolution").addEventListener("transitionend", resetCountdown);
})();
/* Background */
#countdown-background {
height: 50px;
width: 100%;
box-sizing: border-box;
border: 1px solid #ebebeb;
background: linear-gradient(to right, #6419cd, #3273fa);
}
/* Fill */
#countdown-evolution {
height: 100%;
width: 100%;
transform-origin: left;
background-color: #ffffff;
}
/* Reset */
.countdown-reset {
transition: transform 15s linear;
transform: scaleX(0);
}
/* Reference */
.fixed-background {
height: 50px;
width: 100%;
box-sizing: border-box;
background: linear-gradient(to right, #6419cd, #3273fa);
}
<!DOCTYPE html>
<html lang="en>
<head>
<meta charset="UTF-8>
<title>Countdown</title>
</head>
<body>
<div id="countdown-background>
<div id="countdown-evolution></div>
</div>
<div class="fixed-background></div>
</body>
</html>
×
I welcome any advice on achieving the desired outcome. Thank you.