分享纯CSS3编写的的精美动画进度条(附源码)

加载动画和进度条的真正目的是让用户了解任务的进度,有很多的基于JavaScript的动画,但我决定切换到CSS3。 在本教程中,我决定制作动画的进度条,使用纯CSS:没有flash,没有图像,没有脚本。他能够动态的加载变化此外,我专注于寻找最简单的办法做到这一点。这里的例子:

 

 

 

HTML标记:

我们需要的是这两个div,第一个div将代表主容器和圆角和阴影效果,第二个div的实际进度条。 我添加了一个输入和一个按钮控制和播放进度条。  

<div id="prbar">
  <div id="prpos">
  </div>
</div>

<input id="moveTo" value="57" style="width:30px;" />%
<button onclick="MoveTo();return false;">Move</button>

The CSS :

#prbar {
    margin:5px;
    width:500px;
    background-color:#dddddd;
    overflow:hidden;
    
    /* 边框效果 */
    border: 1px solid #bbbbbb;
    -moz-border-radius: 15px;
    border-radius: 15px;
            
    /* 为进度条增加阴影效果 */
    -webkit-box-shadow: 0px 2px 4px #555555;
    -moz-box-shadow: 0px 2px 4px #555555;
    box-shadow: 0px 2px 4px #555555;            
}
        
/* No rounded corners for Opera, because the overflow:hidden dont work with rounded corners */
doesnotexist:-o-prefocus, #prbar {
  border-radius:0px;
}
        
#prpos {
    width:0%;
    height:30px;
    background-color:#3399ff;
    border-right:1px solid #bbbbbb;
           
    /* CSS3 进度条渐变 */
    transition: width 2s ease;
    -webkit-transition: width 0s ease;
    -o-transition: width 0s ease;
    -moz-transition: width 0s ease;
    -ms-transition: width 0s ease;
   
    /* CSS3 Stripes */
    background-image: linear-gradient(135deg,#3399ff 25%,#99ccff 25%,#99ccff 50%, #3399ff 50%, #3399ff 75%,#99ccff 75%,#99ccff 100%);
    background-image: -moz-linear-gradient(135deg,#3399ff 25%,#99ccff 25%,#99ccff 50%, #3399ff 50%, #3399ff 75%,#99ccff 75%,#99ccff 100%);
    background-image: -ms-linear-gradient(135deg,#3399ff 25%,#99ccff 25%,#99ccff 50%, #3399ff 50%, #3399ff 75%,#99ccff 75%,#99ccff 100%);
    background-image: -o-linear-gradient(135deg,#3399ff 25%,#99ccff 25%,#99ccff 50%, #3399ff 50%, #3399ff 75%,#99ccff 75%,#99ccff 100%);
    background-image: -webkit-gradient(linear, 100% 100%, 0 0,color-stop(.25, #99ccff), color-stop(.25, #3399ff),color-stop(.5, #3399ff),color-stop(.5, #99ccff),color-stop(.75, #99ccff),color-stop(.75, #3399ff),color-stop(1, #3399ff));
    background-image: -webkit-linear-gradient(135deg,#3399ff 25%,#99ccff 25%,#99ccff 50%, #3399ff 50%, #3399ff 75%,#99ccff 75%,#99ccff 100%);
    background-size: 40px 40px;

    /* Background stripes animation */
    animation: bganim 3s linear 2s infinite;
    -moz-animation: bganim 3s linear 2s infinite;
    -webkit-animation: bganim 3s linear 2s infinite;
    -o-animation: bganim 3s linear 2s infinite;
    -ms-animation: bganim 3s linear 2s infinite;
}
        
@keyframes bganim {
    from {background-position:0px;} to { background-position:40px;}
}
@-moz-keyframes bganim {
    from {background-position:0px;} to { background-position:40px;}
}
@-webkit-keyframes bganim {
    from {background-position:0px;} to { background-position:40px;}
}
@-o-keyframes bganim {
    from {background-position:0px;} to { background-position:40px;}
}
@-ms-keyframes bganim {
    from {background-position:0px;} to { background-position:40px;}
}

进度条的宽度和高度的需要只能指定一次,指定的宽度在“prbar”和高度在“prpos”内。

您可以修改成任何你想要的背景条纹或任何纹理例如使用线性渐变,你可以画,线,圆

The Animation :

我们的进度条的动画,我们只需要设置另外一个div的宽度,最简单的方法当然是直接指定百分比计算的宽度。

小的JavaScript函数将读取的输入值,并设置宽度为动画的进度条

function MoveTo() {
    var prpos = document.getElementById('prpos');
    prpos.style.width = document.getElementById('moveTo').value + "%";
}

 点我狠狠的下载

本文链接:分享纯CSS3编写的的精美动画进度条(附源码)

posted @ 2013-01-07 09:47  创想中国(羲闻)  阅读(3113)  评论(6编辑  收藏  举报