首页 > 解决方案 > 使用 CSS 的文本滑块

问题描述

我有一个简单的 3 文本我想添加这些文本的向下滑动效果这是我到目前为止的 jsfiddle演示

body {
  font-family: 'Open Sans', 'sans-serif';
  color: #cecece;
  background: #222;
  overflow: hidden;
}

.item-1,
.item-2,
.item-3 {
  position: absolute;
  display: block;
  top: 2em;
  width: 60%;
  font-size: 2em;
  animation-duration: 20s;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}

.item-1 {
  animation-name: anim-1;
}

.item-2 {
  animation-name: anim-2;
}

.item-3 {
  animation-name: anim-3;
}

@keyframes anim-1 {
  0%,
  8.3% {
    left: -100%;
    opacity: 0;
  }
  8.3%,
  25% {
    left: 25%;
    opacity: 1;
  }
  33.33%,
  100% {
    left: 110%;
    opacity: 0;
  }
}

@keyframes anim-2 {
  0%,
  33.33% {
    left: -100%;
    opacity: 0;
  }
  41.63%,
  58.29% {
    left: 25%;
    opacity: 1;
  }
  66.66%,
  100% {
    left: 110%;
    opacity: 0;
  }
}

@keyframes anim-3 {
  0%,
  66.66% {
    left: -100%;
    opacity: 0;
  }
  74.96%,
  91.62% {
    left: 25%;
    opacity: 1;
  }
  100% {
    left: 110%;
    opacity: 0;
  }
}
<p class="item-1">Fast.</p>

<p class="item-2">Slow</p>

<p class="item-3">Much slow</p>
我有一个简单的 3 文本我想添加这些文本的向下滑动效果这是我到目前为止所拥有的 jsfiddle 如果您查看名为 video made sample的标题,我想要的结果可以在此页面中看到

现在它只是向右滑动,我想要一个向下滑动的效果

标签: htmlcsscss-animations

解决方案


把left换成top?

body {
  font-family: 'Open Sans', 'sans-serif';
  color: #cecece;
  background: #222;
  overflow: hidden;
}

.item-1,
.item-2,
.item-3 {
  position: absolute;
  display: block;
  top: 2em;
  width: 60%;
  font-size: 2em;
  animation-duration: 20s;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}

.item-1 {
  animation-name: anim-1;
}

.item-2 {
  animation-name: anim-2;
}

.item-3 {
  animation-name: anim-3;
}

@keyframes anim-1 {
  0%,
  8.3% {
    top: -100%;
    opacity: 0;
  }
  8.3%,
  25% {
    top: 25%;
    opacity: 1;
  }
  33.33%,
  100% {
    top: 110%;
    opacity: 0;
  }
}

@keyframes anim-2 {
  0%,
  33.33% {
    top: -100%;
    opacity: 0;
  }
  41.63%,
  58.29% {
    top: 25%;
    opacity: 1;
  }
  66.66%,
  100% {
    top: 110%;
    opacity: 0;
  }
}

@keyframes anim-3 {
  0%,
  66.66% {
    top: -100%;
    opacity: 0;
  }
  74.96%,
  91.62% {
    top: 25%;
    opacity: 1;
  }
  100% {
    top: 110%;
    opacity: 0;
  }
}
<p class="item-1">Fast.</p>

<p class="item-2">Slow</p>

<p class="item-3">Much slow</p>


推荐阅读