最后没有空格的CSS3 Marquee / Ticker动画 [英] CSS3 Marquee / Ticker animation without space in the end
问题描述
我正在用2个物品集建立一个选取框/旋转木马效果。使用 translateX
循环项目集合
跨度并不困难(
了解这两个集合的宽度可能不同,我怎么才能达到连续性的效果,第一个循环,第一个集合(青色)出现在第二个(洋红色)之后。
任何指向CSS或JS解决方案的指针都非常赞赏... =如果选取框足够大,则可以在动画中间交换其中一个集合。
这就像你可以单独使用CSS一样,我认为
.marquee {width:100%; height:80px;保证金:0汽车;溢出:隐藏;白色空间:nowrap; border:1px solid blue;}。marquee-content {display:inline-block; margin-top:5px; animation:marquee 5s linear infinite;}。item-collection-1 {position:relative;剩下: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;身高:70px;宽度:140px;背景:青色; vertical-align:top; margin-left:15px;}。item2 {display:inline-block;身高:70px;宽度:100px;背景:洋红色; 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 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> < /跨度> < / DIV> < div>
I'm building a marquee/carousel effect with 2 collections of items. Looping both item-collection
spans with translateX
is not difficult (here the fiddle), but I don't like the empty space at the end of each loop.
Knowing that both collections might differ in width, how could I achieve an effect of "continuity" so after the first loop, the first collection (cyan) appears right after the second (magenta).
Any pointer to CSS or JS solutions is highly appreciated... =)
If the marquee is big enough, you can swap one of the collections at mid animation.
This is as far as you can get with CSS alone, I think
.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>
这篇关于最后没有空格的CSS3 Marquee / Ticker动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!