gpt4 book ai didi

javascript - 在页面加载时触发 CSS3 转换

转载 作者:太空狗 更新时间:2023-10-29 13:37:13 24 4
gpt4 key购买 nike

我试图通过 CSS3 宽度过渡实现页面加载的加载效果。这是 demo .

HTML

<div class="skill-bar">
<span class="w70"></span>
</div>

CSS

.skill-bar {
width: 57%;
float: left;
height: 11px;
border-radius: 5px;
position: relative;
margin: 6px 0 12px 0;
border: 2px solid #00edc2;
}
.skill-bar span {
background: #00edc2;
height: 7px;
border-radius: 5px;
display: inline-block;
}
.skill-bar span.w70 {
width: 70%;
}
.skill-bar span {
width: 0;
transition: width 1s ease;
-webkit-transition: width 1s ease;
background-color: #00edc2;
}

它没有按预期工作。我需要在页面加载时进行转换。

但是当我检查元素并选中/取消选中跨度的 width 时,我得到了效果。

如何对页面加载产生相同的效果?

enter image description here

最佳答案

您可以在没有 JavaScript 且使用 CSS 动画没有任何兼容性问题的情况下实现效果:

<div class="skill-bar">
<span class="w70"></span>
</div>

.skill-bar {
width: 57%;
float: left;
height: 11px;
border-radius: 5px;
position: relative;
margin: 6px 0 12px 0;
border: 2px solid #00edc2;
}
.skill-bar span {
background: #00edc2;
height: 7px;
border-radius: 5px;
display: inline-block;
}
.skill-bar span {
animation: w70 1s ease forwards;
}
.skill-bar .w70 {
width: 70%;
}
@keyframes w70 {
from { width: 0%; }
to { width: 70%; }
}

用于 webkit 的 fiddle :http://jsfiddle.net/ySj7t/

关于javascript - 在页面加载时触发 CSS3 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22718441/

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