gpt4 book ai didi

CSS无限水平滚动与关键帧?

转载 作者:行者123 更新时间:2023-12-04 20:43:33 26 4
gpt4 key购买 nike

作为一名学生,我实际上是在做自己的作品集。
对于标题,我尝试创建一个天空效果,使图像水平滚动。我使用了CSS和关键帧,但我遇到的问题是,当图像结束时,它会“重置”并且不会继续平滑滚动。
有什么办法可以使其“无限期地”继续下去? (我将持续时间更改为5s,只是为了不让您等待40s:p)

@keyframes animatedBackground {
from { background-position: 0 0; }
to { background-position: 100% 0; }
}
#header-top {
height: 190px;
background-image: url('http://image.noelshack.com/fichiers/2016/46/1479595480-clouds.png');
background-repeat: repeat-x;
animation: animatedBackground 5s linear infinite;
line-height: 400px;

}
    <div id="header-top">
</div>

最佳答案

我只是裁切了您的图像,所以结尾与开始对齐。然后,我修改了animationBackground关键帧,使其在图像的另一端结束。

Explanation Image

裁剪后的图片:
Cropped Clouds

工作原理

@keyframes animatedBackground {
from {
left: 0px;
}
90% {
left: -562px;
}
100%{left: 0px;}
}
#header-top {
height: 190px;
width: 562px;
overflow-x: auto;
overflow-y: hidden;
}
* {
margin: 0;
padding: 0;
font-family:sans-serif;
}
.inner-cont {
width: 1126px;
position: relative;
animation: animatedBackground 4s linear infinite;
}
img{
border-right:1px solid black;
box-sizing:border-box;
}
<div id="header-top">
<div class='inner-cont'>
<img src="https://archive.org/download/clouds-tiled/clouds-tiled.png" /><img src="https://archive.org/download/clouds-tiled/clouds-tiled.png" />
</div>
</div>
<h3>^ How it actually works(almost) ^</h3>
<h4>The spinback doesn't actually get animated, but it happens <br/>(The line separates the looped images from each other)</h4>


最终结果

@keyframes animatedBackground {
from { background-position: 0px 0; }
to { background-position: -562px 0; }
}
#header-top {
height: 190px;
width:100%;
background-image: url('https://archive.org/download/clouds-tiled/clouds-tiled.png');
background-repeat: repeat-x;
animation: animatedBackground 2s linear infinite;
line-height: 400px;

}
<div id="header-top">
</div>

关于CSS无限水平滚动与关键帧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40698758/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com