css进度动画

165 阅读2分钟

小知识,大挑战!本文正在参与“程序员必备小知识”创作活动。

2.gif

<div class='c'>
		<div class='active bar mint' data-percent='100' data-skill='HTML5'></div>
		<div class='active bar red' data-percent='85' data-skill='CSS3'></div>
		<div class='active bar gray' data-percent='55' data-skill='MySQL'></div>
</div>
@import url(https://fonts.googleapis.com/css?family=Open+Sans:300);
*, *:before, *:after {
  box-sizing: border-box;
}

body {
  font-size: 100%;
  font-family: "Open sans", Arial, sans-serif;
  color: #fff;background-color: #1F1F1F;
}

.c {
  margin: 12rem auto;
  max-width: 600px;
}
@media(max-width: 610px) {
  .c {
    padding: 0 5%;
  }
}
.bar {
  height: 40px;
  width: 0;
  transition: width 1.2s ease-in-out;
  position: relative;
  margin: 0.5rem 0;
  border-radius: 4px;
}
@media(max-width: 350px) {
  .bar {
    margin: 2.5rem 0 0.5rem;
  }
}
.bar.mint {
  background-color: #14C3A2;
  background-image: repeating-linear-gradient(-45deg, #14C3A2, #14C3A2 30px, #22e8c3 30px, #22e8c3 60px);
  background-size: 600px 100%;
  animation: barberpole 12s linear infinite;
  border-bottom: 0.2rem solid #0d7e68;
}
.bar.red {
  background-color: #CF4647;
  background-image: repeating-linear-gradient(-45deg, #CF4647, #CF4647 30px, #da6e6f 30px, #da6e6f 60px);
  background-size: 600px 100%;
  animation: barberpole 12s linear infinite;
  border-bottom: 0.2rem solid #9f292a;
}

.bar.gray {
  background-color: #595B5A;
  background-image: repeating-linear-gradient(-45deg, #595B5A, #595B5A 30px, #727574 30px, #727574 60px);
  background-size: 600px 100%;
  animation: barberpole 12s linear infinite;
  border-bottom: 0.2rem solid #333434;
}
.bar.active:after, .bar.active:before {
  opacity: 1;
}
.bar:before {
  content: attr(data-skill);
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  padding: 10px;
  height: 40px;
  font-style: italic;
  opacity: 0;
  transition: opacity 2s 0.6s;
}
@media(max-width: 350px) {
  .bar:before {
    top: -100%;
    color: #000;
    padding: 10px 0 0;
  }
}
.bar:after {
  content: attr(data-percent) "%";
  display: block;
  position: absolute;
  top: 0;
  right: 0;
  height: 40px;
  padding: 10px;
  opacity: 0;
  transition: opacity 2s 0.6s;
}
@media(max-width: 350px) {
  .bar:after {
    left: 0;
  }
}
@keyframes barberpole {
  from {
    background-position: 0% 0%;
  }
  to {
    background-position: 600px 0%;
  }
}
.bar.active[data-percent="5"] {
  width: 5%;
}

.bar.active[data-percent="10"] {
  width: 10%;
}

.bar.active[data-percent="15"] {
  width: 15%;
}

.bar.active[data-percent="20"] {
  width: 20%;
}

.bar.active[data-percent="25"] {
  width: 25%;
}

.bar.active[data-percent="30"] {
  width: 30%;
}

.bar.active[data-percent="35"] {
  width: 35%;
}

.bar.active[data-percent="40"] {
  width: 40%;
}

.bar.active[data-percent="45"] {
  width: 45%;
}

.bar.active[data-percent="50"] {
  width: 50%;
}

.bar.active[data-percent="55"] {
  width: 55%;
}

.bar.active[data-percent="60"] {
  width: 60%;
}

.bar.active[data-percent="65"] {
  width: 65%;
}

.bar.active[data-percent="70"] {
  width: 70%;
}

.bar.active[data-percent="75"] {
  width: 75%;
}

.bar.active[data-percent="80"] {
  width: 80%;
}

.bar.active[data-percent="85"] {
  width: 85%;
}

.bar.active[data-percent="90"] {
  width: 90%;
}

.bar.active[data-percent="95"] {
  width: 95%;
}

.bar.active[data-percent="100"] {
  width: 100%;
}