我如何在CSS中创建这样的动画

时间:2017-07-19 08:31:22

标签: css twitter-bootstrap

我正在尝试使用css创建一个像bellow一样的动画文本,我该怎么做?

enter image description here

我已经尝试过了:

span1 {
  display: inline-block;
  color: #e74c3c;
  position: relative;
  white-space: nowrap;
  top: 0;
  left: 0;
  -webkit-animation: move 5s;
  -webkit-animation-iteration-count: infinite;
  -webkit-animation-delay: 1s;
}

@keyframes move {
  0% {
    top: 0px;
  }
  20% {
    top: -50px;
  }
  40% {
    top: -100px;
  }
  60% {
    top: -150px;
  }
  80% {
    top: -200px;
  }
  100% {
    top: -300px;
  }
}
<span1>
  web developer<br /> css cowboy<br /> self-facilitating media node<br /> box inside a box<br /> part of the problem
</span1>

但是在我需要删除的最后一个文本之后有一个延迟!

2 个答案:

答案 0 :(得分:1)

请参阅:

*{
  box-sizing: border-box;
}

body {
  background-color: skyblue;
}

div {
  overflow: hidden;
  color: #fff;
  text-align: center;
  font-size: 20px;
  position: relative;
  height: 100px;
  margin-top: 100px;

}

div p {
  height: 100px;
  animation: move  7s infinite linear;
  position: relative;
  bottom: -100px;
  font-size: 36px;
  margin: 0;
}

@keyframes move {
0% {bottom: -100px;}
10%, 20% {bottom: 0px}
40%,50% {bottom: 100px;}
70%,80% {bottom: 200px;}
100% {bottom: 300px}
}
<div>
  <p>50% OFF</p>
  <p>Some Text</p>
  <p>Write by: Ehsan Taghdisi</p>
</div>

答案 1 :(得分:0)

&#13;
&#13;
.anim1 {
  animation: anim1 1.5s infinite;
}

.anim2 {
  animation: anim2 1.5s infinite;
}

@keyframes anim1 {
  0% {
    transform: translateY(-10px);
  }
  50% {
    transform: translateY(-80px);
  }
  100% {
    transform: translateY(-10px);
  }
}

@keyframes anim2 {
  0% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-80px);
  }
  100% {
    transform: translateY(0px);
  }
}
&#13;
<div style="height:40px;overflow:hidden">

  <h1 class="anim1">Hello animation 1</h1>
  <h1 class="anim2">Hello animation 2</h1>
&#13;
&#13;
&#13;