首页 > 解决方案 > 为线条设置动画并使其变成 css3

问题描述

我有一条线。我把它从左向右移动。这很好。但现在我想以 au turn 方式或像蛇一样转动它。我怎样才能做到这一点?

.top {
  position: absolute;
  width: 100px;
  height: 5px;
  left: 0;
  background-color: red;
  animation: move 5s;
}

@-webkit-keyframes move {
  from {}
  to {
    left: 50px;
  }
}
<div class="top"></div>

标签: htmlcssanimationcss-transitions

解决方案


不确定这是否是您所追求的,但希望它有所帮助。

.top {
  position: absolute;
  width: 100px;
  height: 5px;
  left: 0;
  top: 0;
  background-color: red;
  animation: move 5s 1s forwards;
}

@-webkit-keyframes move {
  0% {
    left: 0px;
    top: 0px;
  }
  25% {
    left: 50px;
  }
  50% {
    top: 20px;
    transform: rotate(180deg);
  }
  100% {
    left: 0;
    top: 20px;
    transform: rotate(180deg);
  }
}
<div class="top"></div>


推荐阅读