【问题标题】:Can I move an animated line from right to left?我可以将动画线从右向左移动吗?
【发布时间】:2016-06-02 11:38:14
【问题描述】:

我正在使用 css3 制作从宽度:0 到宽度:100% 的动画线。目前是从左到右移动,但我想让它从右到左开始。这对关键帧是否可行?

这是我的代码

 .content {
   width: 400px;
   height: 200px;
   color: white;
   cursor: pointer;
   text-transform: uppercase;
   padding-bottom: 20px;
   position: relative;
   background: #333;
 }
 .content .line {
   height: 2px;
   background: white;
   position: absolute;
   top: 10px;
   -webkit-animation: dude .75s 1 forwards;
   -moz-animation: dude .75s 1 forwards;
   -o-animation: dude .75s 1 forwards;
   animation: dude .75s 1 forwards;
 }
 @-webkit-keyframes dude {
   0% {
     width: 0;
   }
   100% {
     width: 100%;
   }
 }
 @-moz-keyframes dude {
   0% {
     width: 0;
   }
   100% {
     width: 100%;
   }
 }
 @-o-keyframes dude {
   0% {
     width: 0;
   }
   100% {
     width: 100%;
   }
 }
 @keyframes dude {
   0% {
     width: 0;
   }
   100% {
     width: 100%;
   }
 }
<div class="content">
  <div class="line"></div>
</div>

【问题讨论】:

标签: html css animation


【解决方案1】:

看到这个FIDDLE

添加

.content .line {
   right: 0;
}

.content {
  width: 400px;
  height: 200px;
  color: white;
  cursor: pointer;
  text-transform: uppercase;
  padding-bottom: 20px;
  position: relative;
  background: #333;
}
.content .line {
  height: 2px;
  background: white;
  position: absolute;
  top: 10px;
  right: 0;
  -webkit-animation: dude .75s 1 forwards;
  animation: dude .75s 1 forwards;
}
@-webkit-keyframes dude {
  0% {
    width: 0;
  }
  100% {
    width: 100%;
  }
}
@keyframes dude {
  0% {
    width: 0;
  }
  100% {
    width: 100%;
  }
}
<div class="content">
  <div class="line"></div>
</div>

【讨论】:

【解决方案2】:

尝试为“左”属性而不是宽度设置动画,因为您的元素已经将位置设置为绝对位置。

@keyframes dude {
  0% {
    left: 100%;
  }
  100% {
    left: 0;
  }
}

FIDDLE

【讨论】:

  • 这会保持绘图效果,因为这就是我想要的吗?
【解决方案3】:

animation-direction 更改为reverse

animation: dude .75s 1 reverse;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    • 1970-01-01
    • 2019-11-17
    相关资源
    最近更新 更多