在页面加载时触发CSS3过渡 [英] Trigger CSS3 transition on page load
本文介绍了在页面加载时触发CSS3过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过CSS3宽度转换实现页面加载的加载效果。
这是
I am trying to achieve a loading effect on the page load by CSS3 width transition. Here is the 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;
}
Its not working as expected. I need the transition to happen when the page is loaded.
But when I inspect element and check/uncheck the width
of the span, I get the effect.
How to have the same effect on page load?
解决方案
You can achieve the effect without JavaScript and without any compatibility issue using CSS animation:
<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%; }
}
Fiddle for webkit: http://jsfiddle.net/ySj7t/
这篇关于在页面加载时触发CSS3过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文