scroll div over another div

前端 未结 5 2024
长发绾君心
长发绾君心 2021-02-04 15:42

I have two div with a height of 100%. And when you scroll, I want that the second div over the other scrolls, without scrolling the first up.

Like on this site: http://w

5条回答
  •  后悔当初
    2021-02-04 16:30

    you dont need jquery plugins to do this „scrolling-effect“. you just need some css ;)

    quick and dirty example here:

    HTML

    FIXED PANEL
    Scrolling-Panel 1
    Scrolling-Panel 2
    Scrolling-Panel 3

    CSS

    // reset margin and padding of body and html
        html,body {
           padding:0;
           margin:0;
           background:black;
        }
    
        // allows us to scale all panels inside to full width and height
        #wrapper { 
            position:absolute;
            height:100%;
            width:100%;
        }
    
         // make all panels fullpage  
        .panels { 
            position:relative;
            height:100%;
            min-height:100%;
            width:100%;
            z-index:1000;
        }
    
        // this is the fixed first panel 
        #a{ 
            background:#eee;
            position:fixed;
            color:red;
            top:0;
            left:0;
            /* prevents your fixed panel from being on top of your subsequent panels */
            z-index: -99; 
        }
    
        // the second panel -> after the first fixed panel
        // should get 100% top margin, thats the trick
        #b{ 
           margin-top:100%;
           background:yellow;
        }
    
        #c{
           background:pink;
        }
    
        #d{
           background:green;
        }
    

    demo here:

    jsfiddle Example

    btw: i've made the endzeit-ausstellung.de site.

提交回复
热议问题