Created
May 21, 2012 19:40
-
-
Save tcaddy/2764186 to your computer and use it in GitHub Desktop.
Use CSS to auto expand-retract progress bar infinitely
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* this animation is for progress bars that are not active */ | |
.progress.auto-progress > .bar { | |
-webkit-animation: progress-bar-auto 2s linear infinite; | |
-moz-animation: progress-bar-auto 2s linear infinite; | |
-ms-animation: progress-bar-auto 2s linear infinite; | |
-o-animation: progress-bar-auto 2s linear infinite; | |
animation: progress-bar-auto 2s linear infinite; | |
} | |
/* this animation is for progress bars that are active */ | |
.progress.active.auto-progress > .bar { | |
-webkit-animation: progress-bar-auto-active 2s linear infinite; | |
-moz-animation: progress-bar-auto-active 2s linear infinite; | |
-ms-animation: progress-bar-auto-active 2s linear infinite; | |
-o-animation: progress-bar-auto-active 2s linear infinite; | |
animation: progress-bar-auto-active 2s linear infinite; | |
} | |
/* | |
Keyframe definitions below. | |
We have to have browser-specific keyframe definitions, so this gets repetitive. | |
We also need two definitions for each specific browser targeted: | |
* We have to redefine the CSS animation for the `active` progress bars (based on bootstrap.css) | |
*/ | |
@-webkit-keyframes progress-bar-auto { | |
0% { | |
width: 50%; | |
} | |
25% { | |
width: 100%; | |
} | |
50% { | |
width: 50%; | |
} | |
75% { | |
width: 0%; | |
} | |
100% { | |
width: 50%; | |
} | |
} | |
@-webkit-keyframes progress-bar-auto-active { | |
0% { | |
width: 50%; | |
background-position: 40px 0; | |
} | |
25% { | |
width: 100%; | |
} | |
50% { | |
width: 50%; | |
} | |
75% { | |
width: 0%; | |
} | |
100% { | |
width: 50%; | |
background-position: 0 0; | |
} | |
} | |
@-moz-keyframes progress-bar-auto { | |
0% { | |
width: 50%; | |
} | |
25% { | |
width: 100%; | |
} | |
50% { | |
width: 50%; | |
} | |
75% { | |
width: 0%; | |
} | |
100% { | |
width: 50%; | |
} | |
} | |
@-moz-keyframes progress-bar-auto-active { | |
0% { | |
width: 50%; | |
background-position: 40px 0; | |
} | |
25% { | |
width: 100%; | |
} | |
50% { | |
width: 50%; | |
} | |
75% { | |
width: 0%; | |
} | |
100% { | |
width: 50%; | |
background-position: 0 0; | |
} | |
} | |
@-ms-keyframes progress-bar-auto { | |
0% { | |
width: 50%; | |
} | |
25% { | |
width: 100%; | |
} | |
50% { | |
width: 50%; | |
} | |
75% { | |
width: 0%; | |
} | |
100% { | |
width: 50%; | |
} | |
} | |
@-ms-keyframes progress-bar-auto-active { | |
0% { | |
width: 50%; | |
background-position: 40px 0; | |
} | |
25% { | |
width: 100%; | |
} | |
50% { | |
width: 50%; | |
} | |
75% { | |
width: 0%; | |
} | |
100% { | |
width: 50%; | |
background-position: 0 0; | |
} | |
} | |
@-o-keyframes progress-bar-auto { | |
0% { | |
width: 50%; | |
} | |
25% { | |
width: 100%; | |
} | |
50% { | |
width: 50%; | |
} | |
75% { | |
width: 0%; | |
} | |
100% { | |
width: 50%; | |
} | |
} | |
@-o-keyframes progress-bar-auto-active { | |
0% { | |
width: 50%; | |
background-position: 40px 0; | |
} | |
25% { | |
width: 100%; | |
} | |
50% { | |
width: 50%; | |
} | |
75% { | |
width: 0%; | |
} | |
100% { | |
width: 50%; | |
background-position: 0 0; | |
} | |
} | |
@keyframes progress-bar-auto { | |
0% { | |
width: 50%; | |
} | |
25% { | |
width: 100%; | |
} | |
50% { | |
width: 50%; | |
} | |
75% { | |
width: 0%; | |
} | |
100% { | |
width: 50%; | |
} | |
} | |
@keyframes progress-bar-auto-active { | |
0% { | |
width: 50%; | |
background-position: 40px 0; | |
} | |
25% { | |
width: 100%; | |
} | |
50% { | |
width: 50%; | |
} | |
75% { | |
width: 0%; | |
} | |
100% { | |
width: 50%; | |
background-position: 0 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I initialize this in my HTML markup, I set the width of the
div.bar
element to50%
. That way, if a browser doesn't support CSS animations, at least the user sees something besides a progress bar that is at 0%;