我正在尝试通过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
时,就会得到效果。如何对页面加载产生相同的影响?
最佳答案
使用CSS动画,可以在没有JavaScript且没有任何兼容性问题的情况下实现效果:
<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提琴:http://jsfiddle.net/ySj7t/
关于javascript - 在页面加载时触发CSS3过渡,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22718441/