Page Widget How to - Create animated CSS3 Load bar








Question

We would like to know how to create animated CSS3 Load bar.

Answer

Code from http://fiddle.jshell.net/fV6Eb/3


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
/*<!--from   w ww  . j  a va2s  .  c om-->
Author: Lee Munroe
Project: Animated Loading Bar
Date: April 2012
*/
/* 
Set the container for the bar
*/
.bar {
    height:20px;
    width:200px;
    padding:10px;
    margin:50px auto 0;
    background-color:rgba(0,0,0,.1);
    -webkit-border-radius:25px;
    -moz-border-radius:25px;
    -ms-border-radius:25px;
    border-radius:20px;
    -webkit-box-shadow:0 1px 0 rgba(255,255,255,.03),inset 0 1px 0 rgba(0,0,0,.1);
    -moz-box-shadow:0 1px 0 rgba(255,255,255,.03),inset 0 1px 0 rgba(0,0,0,.1);
    -ms-box-shadow:0 1px 0 rgba(255,255,255,.03),inset 0 1px 0 rgba(0,0,0,.1);
    box-shadow:0 1px 0 rgba(255,255,255,.03),inset 0 1px 0 rgba(0,0,0,.1);
}
/* 
This is the actual bar
*/    
.bar span {
    display:inline-block;
    height:100%;
    width:100%;
    border:1px solid #C04132;
    border-bottom-color:#73271E;
    background-color:#d3d3d3;
    -webkit-border-radius:20px;
    -moz-border-radius:20px;
    -ms-border-radius:20px;
    border-radius:20px;
    -webkit-box-sizing:border-box;
    -moz-box-sizing:border-box;
    -ms-box-sizing:border-box;
    box-sizing:border-box;
    background-image:
        -webkit-linear-gradient(
        -45deg,
        rgba(192,64,50, 1) 25%,
        transparent 25%,
        transparent 50%,
        rgba(192,64,50, 1) 50%,
        rgba(192,64,50, 1) 75%,
        transparent 75%,
        transparent
    );
    background-image:
        -moz-linear-gradient(
        -45deg,
        rgba(192,64,50, 1) 25%,
        transparent 25%,
        transparent 50%,
        rgba(192,64,50, 1) 50%,
        rgba(192,64,50, 1) 75%,
        transparent 75%,
        transparent
    );
    background-image:
        -ms-linear-gradient(
        -45deg,
        rgba(192,64,50, 1) 25%,
        transparent 25%,
        transparent 50%,
        rgba(192,64,50, 1) 50%,
        rgba(192,64,50, 1) 75%,
        transparent 75%,
        transparent
    );
    background-image:
        linear-gradient(
        -45deg,
        rgba(192,64,50, 1) 25%,
        transparent 25%,
        transparent 50%,
        rgba(192,64,50, 1) 50%,
        rgba(192,64,50, 1) 75%,
        transparent 75%,
        transparent
    );
    -webkit-background-size:50px 50px;
    -moz-background-size:50px 50px;
    -ms-background-size:50px 50px;
    background-size:50px 50px;
    -webkit-animation:move 2s linear infinite;
    -moz-animation:move 2s linear infinite;
    -ms-animation:move 2s linear infinite;
    animation:move 2s linear infinite;
    -webkit-border-radius:20px;
    -moz-border-radius:20px;
    -ms-border-radius:20px;
    border-radius:20px;
    overflow: hidden;
    -webkit-box-shadow:inset 0 10px 0 rgba(255,255,255,.2);
    -moz-box-shadow:inset 0 10px 0 rgba(255,255,255,.2);
    -ms-box-shadow:inset 0 10px 0 rgba(255,255,255,.2);
    box-shadow:inset 0 10px 0 rgba(255,255,255,.2);
}
.bar > span:after {
    display: none;
}
/*
Animate the stripes
*/    
@-webkit-keyframes move{
  0% {
      background-position: 0 0;
  }
  100% {
      background-position: 50px 50px;
  }
}    
@-moz-keyframes move{
  0% {
      background-position: 0 0;
  }
  100% {
      background-position: 50px 50px;
  }
}    
@-ms-keyframes move{
  0% {
      background-position: 0 0;
  }
  100% {
      background-position: 50px 50px;
  }
}    
@keyframes move{
  0% {
      background-position: 0 0;
  }
  100% {
      background-position: 50px 50px;
  }
}    
  </style>
</head>
<body>
  <div class="bar">
    <span></span>
</div>
</body>
</html>

The code above is rendered as follows: