某区域固定位置CSS

Fixed Position in a certain area CSS

我正在使用侧边导航栏,我希望它在屏幕上处于固定位置,但我希望它在您向下滚动到这么远后停止固定。有什么办法可以解决这个问题吗?

使用这个功能。滚动时将触发此功能。在函数中编写 if 条件以删除 fixed

$( "#target" ).scroll(function() {
    if($(element).height() === "500px") {
        // remove scroll fixed
        $(scroll).css("position","relative") //or use absolute also.
    }
});

假设它已经修复,您唯一需要做的就是:

if($(window).scrollTop() > 150){
    $('#nav').css('position', 'relative');
}

当然,将 #nav 更改为您自己的选择器,将 150 更改为您想要的值。