【问题标题】:CSS3 Marquee / Ticker animation without space in the endCSS3 Marquee / Ticker 动画最后没有空格
【发布时间】:2016-11-30 15:04:54
【问题描述】:

我正在构建一个包含 2 个项目集合的选框/轮播效果。用translateX 循环两个item-collection 跨度并不难(here the fiddle),但我不喜欢每个循环末尾的空白。

知道两个集合的宽度可能不同,我怎样才能达到“连续”的效果,所以在第一个循环之后,第一个集合(青色)出现在第二个(洋红色)之后。

非常感谢任何指向 CSS 或 JS 解决方案的指针...=)

【问题讨论】:

  • 单独使用 CSS 是不可能的。大多数此类滑块脚本 clone 某些元素 ... 是有原因的

标签: javascript html css css-animations


【解决方案1】:

如果选框足够大,您可以在动画中间交换其中一个集合。

我认为这是仅使用 CSS 所能达到的程度

.marquee {
  width: 100%;
  height: 80px;
  margin: 0 auto;
  overflow: hidden;
  white-space: nowrap;
  border: 1px solid blue;
}
.marquee-content {
  display: inline-block;
  margin-top: 5px;
  animation: marquee 5s linear infinite;
}
.item-collection-1 {
  position: relative;
  left: 0%;
  animation: swap 5s linear infinite;
}
@keyframes swap {
  0%, 50% {
    left: 0%;
  }
  50.01%,
  100% {
    left: 100%;
  }
}
.marquee-content:hover {
  animation-play-state: paused
}
.item1 {
  display: inline-block;
  height: 70px;
  width: 140px;
  background: cyan;
  vertical-align: top;
  margin-left: 15px;
}
.item2 {
  display: inline-block;
  height: 70px;
  width: 100px;
  background: magenta;
  vertical-align: top;
  margin-left: 15px;
  line-height: 14px;
}
/* Transition */

@keyframes marquee {
  0% {
    transform: translateX(0)
  }
  100% {
    transform: translateX(-100%)
  }
}
<div class="marquee">
  <div class="marquee-content">
    <span class="item-collection-1">
      <span class="item1"></span>
    <span class="item1"></span>
    <span class="item1"></span>
    <span class="item1"></span>
    <span class="item1"></span>
    <span class="item1"></span>
    <span class="item1"></span>
    </span>
    <span class="item-collection-2">
      <span class="item2"></span>
    <span class="item2"></span>
    <span class="item2"></span>
    <span class="item2"></span>
    <span class="item2"></span>
    <span class="item2"></span>
    <span class="item2"></span>
    <span class="item2"></span>
    </span>
  </div>
  <div>

【讨论】:

  • 这真的很有趣!如果我们决定用
  • 收藏2个以上也可以
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-11
  • 2013-05-21
  • 1970-01-01
相关资源
最近更新 更多