gpt4 book ai didi

css - 在进度条上叠加内容

转载 作者:太空宇宙 更新时间:2023-11-04 07:06:41 24 4
gpt4 key购买 nike

ul {
margin: 0;
padding: 0;
}
.progress {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
}
li {
position: relative;
margin: 0;
padding: 0;
}
.overlay{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 100;
}
<div>some header content</div>
<ul>
<li>
<div class="overlay">
<span>some stuff</span>
<input/>
<img src="https://upload.wikimedia.org/wikipedia/commons/8/8f/PlayStation_button_X.svg"/>
</div>
<progress class="progress"></progess>
</li>
<li>
<div class="overlay">
<span>some stuff</span>
<input/>
<img src="https://upload.wikimedia.org/wikipedia/commons/8/8f/PlayStation_button_X.svg"/>
</div>
<progress class="progress"></progess>
</li>
</ul>
<div>some footer content</div>

所以我要做的是让列表元素的背景显示该列表项处理的进度。您可以做的是使用所选颜色的 1x1 像素图像并将其设置为背景图像。然后在进度更新时,将背景宽度设置为等于该进度值。

HTML5 现在有一个进度条元素,所以我想知道使用它来实现相同的样式会有多难。到目前为止,这是我所拥有的最好的,而且非常挑剔。实际上有一种简单的方法可以做我忽略的这样的事情吗?如果不是,在这种情况下,我最好还是按照上面描述的老式方法来做。

下面是最终目标的相似示例。

let bgSize = 0;
function increaseWidth() {
bgSize++;
let elements = document.getElementsByTagName('li');
for(let i = 0; i < elements.length; i++) {
elements[i].style.backgroundSize = bgSize + '% 100%';
}
if(bgSize < 100) {
setTimeout(increaseWidth, 500);
}
}
setTimeout(increaseWidth, 500);
li {
background-image: url('https://i.imgur.com/xnhGEBj.jpg');
background-repeat: no-repeat;
background-size: 0%;
display: block;
border: 1px solid #000;
list-style-type: none;
}
ul {
margin: 0;
padding: 0;
}
    <div>some header content</div>
<ul>
<li>
<span>some stuff</span>
<input/>
<img src="https://upload.wikimedia.org/wikipedia/commons/8/8f/PlayStation_button_X.svg"/>
</li>
<li>
<span>some stuff</span>
<input/>
<img src="https://upload.wikimedia.org/wikipedia/commons/8/8f/PlayStation_button_X.svg"/>
</li>
</ul>
<div>some footer content</div>

最佳答案

试试这个:

JS

let bgSize = 0;
let timer = null;

function increaseProgressBar () {
bgSize++;

const elements = document.getElementsByTagName('progress');

for(let i = 0; i < elements.length; i++) {
elements[i].value = bgSize;
}

if(bgSize < 100) {
timer = setTimeout(increaseProgressBar, 500);
}else{
clearTimeout(timer);
timer = null;
}
}

timer = setTimeout(increaseProgressBar, 500);

CSS

ul {
margin: 0;
padding: 0;

li {
border: 1px solid #000;
display: block;
list-style-type: none;
position: relative;

progress {
left: 0;
position: absolute;
right: 0;
}

progress[value] {
appearance: none;
height: 100%;
width: 100%;
z-index: -1;
-webkit-appearance: none;

&::-webkit-progress-bar {
background-color: #fff;
}
}
}
}

HTML

<div>some header content</div>
<ul>
<li>
<span>some stuff</span>
<input/>
<progress value="0" max="100"></progress>
<img src="https://upload.wikimedia.org/wikipedia/commons/8/8f/PlayStation_button_X.svg"/>
</li>
<li>
<span>some stuff</span>
<input/>
<progress value="0" max="100"></progress>
<img src="https://upload.wikimedia.org/wikipedia/commons/8/8f/PlayStation_button_X.svg"/>
</li>
</ul>
<div>some footer content</div>

Demo

关于css - 在进度条上叠加内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51559875/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com