How to hover a Fixed element until it reaches some point

后端 未结 9 2269
栀梦
栀梦 2021-02-07 11:54

I\'ve got a div which I need to be fixed to the bottom of the screen, until it reaches some point after scrolling and stop there and stay. If a user start scrolling back up - ma

9条回答
  •  天涯浪人
    2021-02-07 12:27

    There are two ways to go about it:

    • either go with an absolute pos, and compensate for every scrollbar movement below a certain level
    • or go with a fixed pos, and compensate above a certain level.

    In both case, what you need is "a linear curve with a dent" regarding "position value over scroll value". The best to achieve this are the Math.min/max functions. Hint: The fixed approach is less wobbly for the standstill-part. Unless you need IE6 support (which knows no fixed), go with the #fix solution.

    
    
    
    Absolute
    Fixed

提交回复
热议问题