在一定时间内顺利加载进度条

时间:2017-07-25 17:57:00

标签: html css

嗨我有一个多组进度条,从左到右顺利加载,但加载大约需要5秒。

如何更新它以便从左到右平稳加载并在3秒内完成?

组栏可以有6个或更多组,并且应该在3秒内加载

这里是工作代码的链接

https://codepen.io/Nick1212/pen/WOVLaB?editors=1100

HTML:

<div>
  <h1 class="u-pb--lg text-bold">Grouped ProgressBar Component Examples</h1>
  <div class="space">
    <div> Example: User earning all the points</div>
    <div class="well-ProgressGroup">
      <!-- react-text: 94 --> 
      <!-- /react-text -->
      <div class="well-background--concept1 well-ProgressGroup--progress" style="width: 50%; animation-delay: 1s; z-index: -1; height: 50px;"></div>
      <div class="well-background--concept2 well-ProgressGroup--progress" style="width: 75%; animation-delay: 2s; z-index: -2; height: 50px;"></div>
      <div class="well-background--concept3 well-ProgressGroup--progress" style="width: 100%; animation-delay: 3s; z-index: -3; height: 50px;"></div>
      <div class="well-background--concept4 well-ProgressGroup--progress" style="width: 250%; animation-delay: 4s; z-index: -4; height: 50px;"></div>
      <div class="well-background--concept5 well-ProgressGroup--progress" style="width: 300%; animation-delay: 5s; z-index: -5; height: 50px;"></div>
      <!-- react-text: 101 -->
      <!-- /react-text --> 
    </div>
  </div>
</div>

的CSS:

.well-ProgressGroup {
  display: flex;
  background: #d3d4d5;
  flex-direction: row;
  border-radius: 0.5em;
  overflow: auto;
  position: relative;
  z-index: 1;
}

@keyframes loadbar {
  0% {
    opacity: 1;
  }
  100% {
    transform: translateX(0);
    opacity: 1;
  }
}

.well-ProgressGroup--progress {
  transform: translateX(-100%);
  animation: loadbar 1s linear forwards; 
/*   -webkit-animation: loadbar 1s forwards; */
  opacity: 0;
  background: blue;
}

.well-ProgressGroup--progress:not(:last-child) {
  border-right: 1px solid white;
} 

.well-background--concept1 {
  background: tomato;
}

.well-background--concept2 {
  background: blue;
}

.well-background--concept3 {
  background: purple;
}

.well-background--concept4 {
  background: red;
}

.well-background--concept5 {
  background: green;
} 

3 个答案:

答案 0 :(得分:3)

每个.well-ProgressGroup--progress div在HTML中都有动画延迟内嵌样式,以3s / 5 = 0.6s 0, 0.6s, 1.2s, 1.8s, 2.4s的增量更新这些内容。然后在CSS中将animation: loadbar 1s linear forwards;中的.well-ProgressGroup--progress调整为animation: loadbar 0.6s linear forwards;

第一个更改是让您的条形图一个接一个地填充,没有间隙。第二个是每个酒吧填充的速度。见here

答案 1 :(得分:1)

更新您的animation-delayanimation-duration,以便所有5个动画都需要3个:

&#13;
&#13;
.well-ProgressGroup {
  display: flex;
  background: #d3d4d5;
  flex-direction: row;
  border-radius: 0.5em;
  overflow: auto;
  position: relative;
  z-index: 1;
}

@keyframes loadbar {
  0% {
    opacity: 1;
  }
  100% {
    transform: translateX(0);
    opacity: 1;
  }
}

.well-ProgressGroup--progress {
  transform: translateX(-100%);
  animation: loadbar 0.5s linear forwards; 
  opacity: 0;
  background: blue;
}

.well-ProgressGroup--progress:not(:last-child) {
  border-right: 1px solid white;
} 

.well-background--concept1 {
  background: tomato;
}

.well-background--concept2 {
  background: blue;
}

.well-background--concept3 {
  background: purple;
}

.well-background--concept4 {
  background: red;
}

.well-background--concept5 {
  background: green;
} 
&#13;
<div>
  <h1 class="u-pb--lg text-bold">Grouped ProgressBar Component Examples</h1>
  <div class="space">
    <div> Example: User earning all the points</div>
    <div class="well-ProgressGroup">
      <!-- react-text: 94 --> 
      <!-- /react-text -->
      <div class="well-background--concept1 well-ProgressGroup--progress" style="width: 50%; animation-delay: 0.5s; z-index: -1; height: 50px;"></div>
      <div class="well-background--concept2 well-ProgressGroup--progress" style="width: 75%; animation-delay: 1s; z-index: -2; height: 50px;"></div>
      <div class="well-background--concept3 well-ProgressGroup--progress" style="width: 100%; animation-delay: 1.5s; z-index: -3; height: 50px;"></div>
      <div class="well-background--concept4 well-ProgressGroup--progress" style="width: 250%; animation-delay: 2s; z-index: -4; height: 50px;"></div>
      <div class="well-background--concept5 well-ProgressGroup--progress" style="width: 300%; animation-delay: 2.5s; z-index: -5; height: 50px;"></div>
      <!-- react-text: 101 -->
      <!-- /react-text --> 
    </div>
  </div>
</div>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

您可以在animation-delay属性上使用毫秒而不是秒来减慢动画速度。你还需要改变Alex提到的CSS动画

&#13;
&#13;
.well-ProgressGroup {
  display: flex;
  background: #d3d4d5;
  flex-direction: row;
  border-radius: 0.5em;
  overflow: auto;
  position: relative;
  z-index: 1;
}

@keyframes loadbar {
  0% {
    opacity: 1;
  }
  100% {
    transform: translateX(0);
    opacity: 1;
  }
}

.well-ProgressGroup--progress {
  transform: translateX(-100%);
  animation: loadbar 0.6s linear forwards; 
/*   -webkit-animation: loadbar 1s forwards; */
  opacity: 0;
  background: blue;
}

.well-ProgressGroup--progress:not(:last-child) {
  border-right: 1px solid white;
} 

.well-background--concept1 {
  background: tomato;
}

.well-background--concept2 {
  background: blue;
}

.well-background--concept3 {
  background: purple;
}

.well-background--concept4 {
  background: red;
}

.well-background--concept5 {
  background: green;
} 
&#13;
<div>
  <h1 class="u-pb--lg text-bold">Grouped ProgressBar Component Examples</h1>
  <div class="space">
    <div> Example: User earning all the points</div>
    <div class="well-ProgressGroup">
      <!-- react-text: 94 --> 
      <!-- /react-text -->
      <div class="well-background--concept1 well-ProgressGroup--progress" style="width: 50%; animation-delay: 600ms; z-index: -1; height: 50px;"></div>
      <div class="well-background--concept2 well-ProgressGroup--progress" style="width: 75%; animation-delay: 1200ms; z-index: -2; height: 50px;"></div>
      <div class="well-background--concept3 well-ProgressGroup--progress" style="width: 100%; animation-delay: 1800ms; z-index: -3; height: 50px;"></div>
      <div class="well-background--concept4 well-ProgressGroup--progress" style="width: 250%; animation-delay: 2400ms; z-index: -4; height: 50px;"></div>
      <div class="well-background--concept5 well-ProgressGroup--progress" style="width: 300%; animation-delay: 3000ms; z-index: -5; height: 50px;"></div>
      <!-- react-text: 101 -->
      <!-- /react-text --> 
    </div>
  </div>
</div>
&#13;
&#13;
&#13;