我可以从右到左移动动画线吗?

时间:2016-06-02 11:38:15

标签: css html5 css3 animation

我用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>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:2)

请参阅此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>

答案 1 :(得分:0)

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

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

FIDDLE

答案 2 :(得分:0)

animation-direction更改为reverse

animation: dude .75s 1 reverse;