How to stick fixed div of height more than viewport to body

后端 未结 5 952
生来不讨喜
生来不讨喜 2021-01-18 05:50

I know about the positioning of div (fixed, absolute and relative). I can attach a fixed div to body so that it will stick to the same position while scrolling body. Here I

5条回答
  •  生来不讨喜
    2021-01-18 06:27

    Taking the Facebook sidebar as an example it seems that as soon as the browser scrolls vertically to a certain threshold (the top of the screen hits the top of the final ad in the sidebar) it changes the class on the sidebar.

    At this point it sets the css position to fixed and sets a top style on the sidebar of -???px so that it appears at that threshold has not moved but when you scroll down it will not scroll anymore.

    You can detect the offset of a particular element using the jquery scrollTop() function. http://api.jquery.com/scrollTop/

提交回复
热议问题