问题描述
我有一个 <div>
,其中包含我的幻灯片的全屏背景图片。由于包的原因,我无法使用 background-attachment: fixed;
。如果没有此属性,我的图像会失真并出现在幻灯片中。我不能使用`background-attachment: fixed;在这里。
<div ref={parallaxDiv} className="image" />
.image {
position: relative;
width: 100%;
height: 100%;
background: url("https://placeimg.com/640/480/people") no-repeat center center;
background-size: cover;
}
对于设置为覆盖的背景图像,是否有 background-attachment: fixed;
的替代方法?
解决方法
这对你有用
.image {
background: url("https://placeimg.com/640/480/people");
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
}