How to hover a Fixed element until it reaches some point

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

    $(window).scroll(function () {
        if ($(this).scrollTop() < $(document).height() - 81) {
            $('#bottom_pic').css("position", "fixed");
            $('#bottom_pic').css('bottom', "0px");
        }
        else {
            $('#bottom_pic').css("position", "absolute");
            $('#bottom_pic').css({'top':(($(document).height())-81)+'px'});
        }
    });
    

    This will make the div fixed at bottom until its 81px away from the top. Once it reaches there, it will stay there.

提交回复
热议问题