【发布时间】:2021-04-14 10:22:17
【问题描述】:
我目前正在尝试让我的图像幻灯片重复播放,以便在幻灯片结束时跳回开头或与第一张图像一起重复。不知何故,它不起作用,我不明白。
这是我的演示:
#logo-gallery-wrapper {
overflow: hidden;
position: relative;
}
#logo-gallery {
animation: scroll-left 220s linear infinite;
animation-iteration-count: infinite;
margin: 0;
padding: 0;
position: relative;
list-style-type: none;
display: flex;
}
#logo-gallery .logo-gallery-figure {
margin: 0;
padding: 0 1.6rem;
overflow: hidden;
}
#logo-gallery .logo-gallery-figure img {
height: auto;
max-height: 50px;
position: relative;
filter: grayscale(1);
transition: all .4s;
}
#logo-gallery .logo-gallery-figure img:hover {
filter: grayscale(0);
}
@keyframes scroll-left {
0% {
transform: translateX(0)
}
100% {
transform: translateX(calc(-1000rem + 100vw))
}
}
<div id="logo-gallery-wrapper">
<ul id="logo-gallery">
<li>
<figure class="logo-gallery-figure">
<img src="https://www.ikea.com/de/de/static/ikea-logo.f88b07ceb5a8c356b7a0fdcc9a563d63.svg">
</figure>
</li>
<li>
<figure class="logo-gallery-figure">
<img src="https://www.ikea.com/de/de/static/ikea-logo.f88b07ceb5a8c356b7a0fdcc9a563d63.svg">
</figure>
</li>
<li>
<figure class="logo-gallery-figure">
<img src="https://www.ikea.com/de/de/static/ikea-logo.f88b07ceb5a8c356b7a0fdcc9a563d63.svg">
</figure>
</li>
<li>
<figure class="logo-gallery-figure">
<img src="https://www.ikea.com/de/de/static/ikea-logo.f88b07ceb5a8c356b7a0fdcc9a563d63.svg">
</figure>
</li>
<li>
<figure class="logo-gallery-figure">
<img src="https://www.ikea.com/de/de/static/ikea-logo.f88b07ceb5a8c356b7a0fdcc9a563d63.svg">
</figure>
</li>
<li>
<figure class="logo-gallery-figure">
<img src="https://www.ikea.com/de/de/static/ikea-logo.f88b07ceb5a8c356b7a0fdcc9a563d63.svg">
</figure>
</li>
<li>
<figure class="logo-gallery-figure">
<img src="https://www.ikea.com/de/de/static/ikea-logo.f88b07ceb5a8c356b7a0fdcc9a563d63.svg">
</figure>
</li>
</ul>
</div>
【问题讨论】:
-
calc()函数似乎不支持模数运算,这本来是我的建议。有一个用最少的 JS here 的答案。 -
你确定不想在这里使用任何 JS 吗?没有它,您将复制您的元素并制作一个 hacky 关键帧动画,在结束/开始时交换它们。
-
它似乎正在工作......只是你给了动画一个 220 秒的时间来执行,所以需要等待很长时间才能重新开始。另外,计算可能不太准确。 (您可以将动画更改为
animation: scroll-left 2s linear infinite;以查看它是否正常工作) -
@SomoKRoceS 嗯,我明白了。但在这种情况下,我的客户不会因为阅读速度而很高兴。
-
这样的话,速度还可以。您也许应该以不同的方式计算翻译,因为它在 220 秒结束之前就消失了。