Overlay divs on scroll

前端 未结 3 434
日久生厌
日久生厌 2020-12-29 16:58

Instead of scrolling down the page to view a bunch of divs, I would like them to overlay in the same place-- one stacked on top the next -- when you scroll. So, you would sc

3条回答
  •  死守一世寂寞
    2020-12-29 17:38

    In order to achieve the parallax effect with CSS only, all you need to do is use the CSS background-attachment property and set it to fixed and also add min-height

    .parallax {
        /* The image used */
        background-image: url("img_parallax.jpg");
    
        /* Set a specific height */
        min-height: 500px; 
    
        /* Create the parallax scrolling effect */
        background-attachment: fixed;
        background-position: center;
        background-repeat: no-repeat;
        background-size: cover;
       }
    

    Check out this link:
    https://www.w3schools.com/howto/tryhow_css_parallax_demo.htm

提交回复
热议问题