为了账号安全,请及时绑定邮箱和手机立即绑定

从右向左停止动画

从右向左停止动画

尚方宝剑之说 2024-01-03 14:29:13
我希望这个进度条仅从左到右从文本开始动画。动画从右到左结束后,它会从某个点开始从右到左开始动画。注意,我需要使用弹性框和文本宽度。.table-bars .bar-box .text {    height: 100%;    margin: 0 30px 0 200px;    width: 200px;    text-align:right;}.bar-box {    margin-bottom:20px;   }.table-bars div .progress {    background-color: #0071b9;    border-radius: 20px;    border-right: 13px solid rgb(0, 173, 239);    -webkit-animation: progressBar 2s ease-in-out;    -webkit-animation-fill-mode:both;    -moz-animation: progressBar 2s ease-in-out;    -moz-animation-fill-mode:both;    height: 20px;}@-webkit-keyframes progressBar {  0% { width: 0; }  100% { width: 100%; }}@-moz-keyframes progressBar {  0% { width: 0; }  100% { width: 100%; }}.bar-box {    display: flex;}<div class="table-bars">     <div class="bar-box">           <div class="text"><span>TEXT</span></div>           <div class="progress"></div>     </div>     <div class="bar-box">           <div class="text"><span>Another TEXT</span></div>           <div class="progress"></div>     </div></div>
查看完整描述

1 回答

?
慕田峪9158850

TA贡献1794条经验 获得超7个赞

您需要添加flex-shrink:0以避免文本尖叫,因为您正在设置width:100%

.table-bars .bar-box .text {

  height: 100%;

  margin: 0 30px 0 200px;

  width: 200px;

  text-align: right;

  flex-shrink:0;

}


.bar-box {

  margin-bottom: 20px;

}


.table-bars div .progress {

  background-color: #0071b9;

  border-radius: 20px;

  border-right: 13px solid rgb(0, 173, 239);

  animation: progressBar 2s ease-in-out;

  animation-fill-mode: both;

  height: 20px;

}


@keyframes progressBar {

  0% {

    width: 0;

  }

  100% {

    width: 100%;

  }

}


.bar-box {

  display: flex;

}

<div class="table-bars">

  <div class="bar-box">

    <div class="text"><span>TEXT</span></div>

    <div class="progress"></div>

  </div>

  <div class="bar-box">

    <div class="text"><span>Another TEXT</span></div>

    <div class="progress"></div>

  </div>

</div>

或者用动画flex-grow代替width

.table-bars .bar-box .text {

  height: 100%;

  margin: 0 30px 0 200px;

  width: 200px;

  text-align: right;

  flex-shrink:0;

}


.bar-box {

  margin-bottom: 20px;

}


.table-bars div .progress {

  background-color: #0071b9;

  border-radius: 20px;

  border-right: 13px solid rgb(0, 173, 239);

  animation: progressBar 2s ease-in-out;

  animation-fill-mode: both;

  height: 20px;

}


@keyframes progressBar {

  0% {

    flex-grow: 0;

  }

  100% {

    flex-grow: 1;

  }

}


.bar-box {

  display: flex;

}

<div class="table-bars">

  <div class="bar-box">

    <div class="text"><span>TEXT</span></div>

    <div class="progress"></div>

  </div>

  <div class="bar-box">

    <div class="text"><span>Another TEXT</span></div>

    <div class="progress"></div>

  </div>

</div>


查看完整回答
反对 回复 2024-01-03
  • 1 回答
  • 0 关注
  • 34 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信