这个问题有一个答案,它在选框的每次迭代结束时留下了很多空白空间:CSS3 Marquee Effect
有没有办法使用CSS3实现平滑的<marquee></marquee>
效果,而不会留下这个空间?
我有很多小元素,看起来有点像SO的蓝色标签,专门填充选框的内容,而不是一个连续的主体或一面文字墙。
答案 0 :(得分:11)
以下是您可以做的示例,并通过设置延迟和持续时间来控制文本之间的空间
.marquee {
background-color: #ddd;
width: 500px;
margin: 0 auto;
overflow: hidden;
white-space: nowrap;
}
.marquee span {
display: inline-block;
font-size: 20px;
position: relative;
left: 100%;
animation: marquee 8s linear infinite;
}
.marquee:hover span {
animation-play-state: paused;
}
.marquee span:nth-child(1) {
animation-delay: 0s;
}
.marquee span:nth-child(2) {
animation-delay: 0.8s;
}
.marquee span:nth-child(3) {
animation-delay: 1.6s;
}
.marquee span:nth-child(4) {
animation-delay: 2.4s;
}
.marquee span:nth-child(5) {
animation-delay: 3.2s;
}
@keyframes marquee {
0% { left: 100%; }
100% { left: -100%; }
}
&#13;
<p class="marquee">
<span>this is a</span>
<span>simple marquee</span>
<span>using css</span>
<span>only tech</span>
<span>with a delay</span>
</p>
&#13;
答案 1 :(得分: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 15s linear infinite;
}
.item-collection-1 {
position: relative;
left: 0%;
animation: swap 15s 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><img src="https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png" height="80"></span>
<span class="item1"></span>
<span><img src="https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png" height="80"></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 :(得分:0)
CSS3字幕效果,没有空白
Horizontal Marquee
水平,其中一个右和一个左:https://codepen.io/Rayeesac/pen/JjGEYRZ
Vertical Marquee
垂直,其中一个顶部和一个底部:https://codepen.io/Rayeesac/pen/eYJgpVy