- background-attachment:fixed
在你想要固定的图片上加上上述css代码即可,但这种方式容易导致页面卡顿。 - 伪类方案*(页面不卡顿)
#imgMain {
@include clearfix;
overflow: hidden;
position: relative;
&::before {
position: fixed; // 保持不动
width: 99.9%;
height: 99.9%;
top: 0;
left: 0;
content: ' ';
background-image: url('../../assets/background3jpeg.webp');
background-repeat: no-repeat;
background-size: 99.9% 99.9%;
will-change: transform; // 减轻页面卡顿
z-index: -1; // 放置底层
}
}