动画时背景图像不平滑(某种闪烁),我无法使其从图像中心缩放。
这是我要建立的个人网站。
*{margin: 0;padding: 0;}
body
{
background-color: #0C090A;
background-image: url(../abstract-bg.png);
animation: zoom 30s infinite;
-webkit-animation: zoom 30s infinite;
}
@keyframes zoom {
0% {
background-size: 100%;
}
50% {
background-size: 105%;
}
100% {
background-size: 100%;
}
}
我想将背景图像(1920 * 1080)缓慢缩放到原始大小的105%(或类似大小),然后再返回100%。另外,如果可能,请使其从中心而不是左上角缩放。感谢您的帮助。
最佳答案
是的,您当然可以:)
只需添加
background-position:center center;
background-repeat:no-repeat;
在体内的CSS
并添加
html{
height: 100%;
}
完整的CSS代码:
* {
margin: 0;
padding: 0;
}
html {
height: 100%;
}
body {
background-color: #0C090A;
background-image: url(https://images.pexels.com/photos/556416/pexels-photo-556416.jpeg);
animation: zoom 30s infinite;
-webkit-animation: zoom 30s infinite;
background-position: center center;
background-repeat: no-repeat;
}
@keyframes zoom {
0% {
background-size: 100%;
}
50% {
background-size: 150%;
}
100% {
background-size: 100%;
}
}
您可以测试代码:
https://playcode.io/358401
关于css - 如何使用CSS中的背景图像无限平滑地平滑放大和缩小,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56826905/