Div that follows scroll (not position:fixed)

后端 未结 4 1784
迷失自我
迷失自我 2021-01-23 21:43

I found it sometime ago and now I can\'t. I want to find something like the shopping cart at the apple store, it\'s a div thats not positioned absolute nor fixed, for instance,

4条回答
  •  悲哀的现实
    2021-01-23 22:39

    The app store uses the following css:

    div.cto div.slider-content {
        height: 100%;
        overflow: visible;
        padding-bottom: 20px;
        position: absolute;
        right: 0;
        top: -10px;
        width: 169px;
    }
    
    div.cto div.pinned_top div#secondary {
        position:absolute;top:0;right:0;
    }
    
    div.cto div.floating div#secondary {
        position:fixed;top:0;
    }
    

    Using javascript, the class of the div is changed from 'pinned_top' to 'floating' when you scroll down.

    About the javascript:

    • To determine the number of pixels scrolled: $('html').scrollTop()
    • To listen to scroll events: http://api.jquery.com/scroll/

提交回复
热议问题