我试图通过 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
时,我得到了效果。
如何对页面加载产生相同的效果?
最佳答案
您可以在没有 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/