gpt4 book ai didi

html - 在没有动画的情况下更改背景位置

转载 作者:太空宇宙 更新时间:2023-11-04 01:47:41 25 4
gpt4 key购买 nike

我有这段代码可以在 CSS 和 HTML 中连续改变背景:

animation: animated 10s linear infinite;

@keyframes animated {
0% { background-position: 0px bottom; }
25% { background-position: -200px bottom; }
50% { background-position: -400px bottom; }
75% { background-position: -600px bottom; }
}

目前背景在动画中移动,但我想一次性切换背景位置 - 所以看起来图像发生变化而不是移动。

仅使用 CSS 有可能吗?

最佳答案

你需要做的是,而不是

25% { background-position: -200px bottom; }
50% { background-position: -400px bottom; }

你这样做是这样的:

25.01%, 50% { background-position: -200px bottom; }
50.01%, 75% { background-position: -400px bottom; }

因此,您将几乎消除从一个关键帧过渡到另一个关键帧所需的时间。

演示:jsFiddle

*{ padding:0; margin:0; }
#bg{ width:100%; height:100vh;
background: url('//www.planwallpaper.com/static/images/Fall-Nature-Background-Pictures.jpg') no-repeat;
animation: slideshow 5s infinite;
}
@keyframes slideshow {
0%, 25% { background-position: 0px bottom; }
25.01%, 50% { background-position: -200px bottom; }
50.01%, 75% { background-position: -400px bottom; }
75.01%, 100% { background-position: -600px bottom; }
}
<div id="bg"></div>

关于html - 在没有动画的情况下更改背景位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44151769/

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