先抛效果图
核心属性:background-attachment
核心代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>视觉滚差</title>
<style>
*{
margin:0;
padding:0;
}
section {
height: 100vh;
text-align:center;
line-height:100vh;
color:#fff;
font-size:50px;
}
.g-word{
background:#4e4e4e;
}
.g-img:nth-of-type(2) {
background-image: url('./1.jpg');
}
.g-img:nth-of-type(4) {
background-image: url('./2.jpg');
}
.g-img:nth-of-type(6) {
background-image: url('./3.jpg');
}
.g-img{
background-attachment: fixed;
background-size: cover;
background-position: center center;
}
</style>
</head>
<body>
<section class="g-word">Header</section>
<section class="g-img">IMG1</section>
<section class="g-word">Content1</section>
<section class="g-img">IMG2</section>
<section class="g-word">Content2</section>
<section class="g-img">IMG3</section>
<section class="g-word">Footer</section>
</body>
</html>