主要是利用背景图片的background-attachment属性
    image.png
    设置盒子的背景图片不会跟随页面的滚动而移动
    可以类比 :position: fixed; 来看

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <!-- <meta name="viewport" content="width=device-width">-->
    6. <title>Title</title>
    7. <link rel="stylesheet" href="./index.css">
    8. </head>
    9. <body>
    10. <div id="container">
    11. <section id="img1" class="img">IMG1</section>
    12. <section id="content1">CONTENT1</section>
    13. <section id="img2" class="img">IMG2</section>
    14. <section id="content2">CONTENT2</section>
    15. <section id="img3" class="img">IMG3</section>
    16. <section id="content3">CONTENT3</section>
    17. </div>
    18. </body>
    19. </html>
    1. *{
    2. padding: 0;
    3. margin: 0;
    4. }
    5. ::-webkit-scrollbar{
    6. display: none;
    7. }
    8. #container{
    9. width: 100vw;
    10. height: auto;
    11. }
    12. section{
    13. height: 100vh;
    14. background: #c4cbcf;
    15. color: #fff;
    16. font-size: 20vh;
    17. display: flex;
    18. align-items: center;
    19. justify-content: center;
    20. }
    21. .img{
    22. background-size: auto;
    23. overflow: hidden;
    24. background-position: center;
    25. background-attachment: fixed;
    26. background-repeat: no-repeat;
    27. max-width: 100%;
    28. user-select: none;
    29. cursor: default;
    30. }
    31. #img1{
    32. background-image: url("./images/1.jpg");
    33. }
    34. #img2{
    35. background-image: url("./images/2.jpg");
    36. }
    37. #img3{
    38. background-image: url("./images/3.jpg");
    39. }