我正在尝试为进度条(HTML5<progess>
标记)设置动画。我设法设置了 Shadow DOM 元素的样式,但我无法为背景设置动画(重复线性渐变)。它适用于 Firefox,但不适用于 Chrome 和 Edge。
<ins>
它不起作用我的意思是,显示了条纹背景,但它不是动画的</ins>
似乎@keyframe
动画定义在阴影边界之外具有不同的范围。
<ins>
如何打破 Shadow DOM 边界的范围?
或者有没有一种方法可以覆盖用户代理影子 DOM 实现?
</ins>
<ins>
如果有 No-JS 解决方案,我会很高兴
</ins>
.progress {
position: relative;
}
.progress::before {
content: attr(title);
position: absolute;
z-index: 100;
width: 100%;
height: 100%;
display: -webkit-box;
display: flex;
-webkit-box-align: center;
align-items: center;
-webkit-box-pack: center;
justify-content: center;
text-align: center;
font-size: 2rem;
font-weight: 700;
line-height: 1.4;
}
progress[value] {
display: block;
width: 100%;
min-height: 4rem;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border: none;
border-radius: 10px;
box-shadow: inset 4px 4px 4px rgba(84, 30, 8, 0.2);
background-color: rgba(149, 250, 61, 0.1);
border: 1px solid #ccc;
}
progress[value]::-webkit-progress-inner-element {
border-radius: 10px;
overflow: hidden;
}
progress[value]::-webkit-progress-bar {
border-radius: 10px;
/* box-shadow: inset 4px 4px 4px rgba(84, 30, 8, 0.2); */
background-color: transparent;
}
progress[value]::-webkit-progress-value {
border-radius: 10px 0 0 10px / 10px 0 0 10px;
box-shadow: inset 2px 2px 2px rgba(84, 30, 8, 0.2);
background-color: #95fa3c;
position: relative;
background-image: repeating-linear-gradient(45deg, transparent 0, transparent 6px, rgba(0, 0, 0, 0.1) 6px, rgba(0, 0, 0, 0.1) 12px);
background-size-x: 800942px; /* empirical value */
-webkit-animation: colorrush 3s infinite linear;
animation: colorrush 3s infinite linear;
}
progress[value]::-moz-progress-bar {
border-radius: 10px 0 0 10px / 10px 0 0 10px;
box-shadow: inset 2px 2px 2px rgba(84, 30, 8, 0.2);
background-color: #95fa3c;
position: relative;
background-image: repeating-linear-gradient(45deg, transparent 0, transparent 6px, rgba(0, 0, 0, 0.1) 6px, rgba(0, 0, 0, 0.1) 12px);
background-size: 800942px; /* empirical value */
animation: colorrush 3s infinite linear;
}
@-webkit-keyframes colorrush {
0% {
background-color: #95fa3c;
background-position-x: 0;
}
50% {
background-color: #c4eea0;
}
100% {
background-color: #95fa3c;
background-position-x: 152px; /* empirical value */
}
}
@keyframes colorrush {
0% {
background-color: #95fa3c;
background-position-x: 0;
}
50% {
background-color: #c4eea0;
}
100% {
background-color: #95fa3c;
background-position-x: 152px; /* empirical value */
}
}
html {
font-size: 62.5%;
font-family: sans-serif;
}
body {
font-size: 1.6rem;
}
<div class="progress" title="125 / 150 (83.33%)">
<progress max="150" value="125">125 / 150</progress>
</div>