滚动视差
主要是利用background-attachment
属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
body{
height: 100vh;
}
.bgimg-1,
.bgimg-2,
.bgimg-3 {
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
min-height: 100%;
display: flex;
justify-content: center;
align-items: center;
font-size: 50px;
color: #fff;
}
.bgimg-1 {
background-image: url("./img1.jpg");
}
.bgimg-2 {
background-image: url("./img2.jpg");
}
.bgimg-3 {
background-image: url("./img3.jpg");
}
.content{
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
font-size: 50px;
}
</style>
</head>
<body>
<div class="bgimg-1">img1</div>
<div class="content">11</div>
<div class="bgimg-2">img2</div>
<div class="content">22</div>
<div class="bgimg-3">img3</div>
<div class="content">33</div>
</body>
</html>
效果展示
滚动视差