答案 0 :(得分:1)
使用以下代码解决:
const ParallaxImgStyled = styled.div`
background-image: url(${(props) => props.imgUrl});
background-size: cover;
/* Set a specific height */
min-height: 450px;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
position: relative;
z-index: 0;
&:before {
background: rgba(0, 0, 0, 0.6);
content: "";
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
z-index: -1;
}
`;