最终没有空间的CSS3 Marquee / Ticker动画

时间:2016-11-29 19:00:57

标签: javascript html css3 css-animations

我用2个项目集合构建选框/旋转木马效果。将item-collection两个translateX范围转为procedure TForm1.Button1Click(Sender: TObject); begin ProccesSupervisor:= TMyThread0.Create(True); ProccesSupervisor.FreeOnTerminate:=true; ProccesSupervisor.Priority := tpNormal; ProccesSupervisor.Resume; end; procedure TMyThread0.Execute; begin repeat //some code here until ProccesSupervisor.terminated=true; end; procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin ProccesSupervisor.Terminate; ProccesSupervisor.WaitFor; end; 并不困难(here the fiddle),但我不喜欢每个循环结束时的空白区域。

enter image description here

知道这两个系列的宽度可能不同,我怎样才能达到"连续性"因此,在第一个循环之后,第一个集合(青色)出现在第二个集合(品红色)之后。

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

1 个答案:

答案 0 :(得分:5)

如果选取框足够大,您可以在动画中期交换其中一个收藏夹。

这就是你可以单独使用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>

相关问题