How to hover a Fixed element until it reaches some point

后端 未结 9 2271
栀梦
栀梦 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:23

    $(window).scroll(function(){
      if($(this).scrollTop() < $(document).height() -1000){
        $(selector).css("position", "fixed");
        $(selector).css("bottom","0");
      }
      else
      {
        $(selector).css('bottom', "81px");
      }
    });
    

    I tried this code and it works for $(document).height() -500 ). But for some reason i can't understand it does not work when the value 500 is decreased to 100 or 81.

    Try changing this value and see the difference

提交回复
热议问题