主要是利用背景图片的background-attachment属性
设置盒子的背景图片不会跟随页面的滚动而移动
可以类比 :position: fixed; 来看
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><!-- <meta name="viewport" content="width=device-width">--><title>Title</title><link rel="stylesheet" href="./index.css"></head><body><div id="container"><section id="img1" class="img">IMG1</section><section id="content1">CONTENT1</section><section id="img2" class="img">IMG2</section><section id="content2">CONTENT2</section><section id="img3" class="img">IMG3</section><section id="content3">CONTENT3</section></div></body></html>
*{padding: 0;margin: 0;}::-webkit-scrollbar{display: none;}#container{width: 100vw;height: auto;}section{height: 100vh;background: #c4cbcf;color: #fff;font-size: 20vh;display: flex;align-items: center;justify-content: center;}.img{background-size: auto;overflow: hidden;background-position: center;background-attachment: fixed;background-repeat: no-repeat;max-width: 100%;user-select: none;cursor: default;}#img1{background-image: url("./images/1.jpg");}#img2{background-image: url("./images/2.jpg");}#img3{background-image: url("./images/3.jpg");}
