我知道渐变只是与它们所应用的元素的尺寸相匹配。尽管如此,有没有办法在视觉上使渐变静态并屏蔽掉不应该可见的部分?
我的目的是让倒计时器在接近其演变的终点时变得更暗。目前,我的渐变保留了左侧和右侧的颜色,同时简单地减少了中间的颜色:
(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;
border: 1px solid #ebebeb;
background: linear-gradient(to right, #6419cd, #3273fa);
}
<!DOCTYPE html>
<html>
<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>
我已经尝试过制作countdown-background
渐变和countdown-evolution
纯色,这基本上就是我所追求的。然而,这带来的问题比它解决的问题还要多。因为现在我必须修复我的倒计时器,但我似乎无法让它看起来和以前一样:
米脂
慕运维8079593
相关分类