Css 在某一区域内的固定位置

Css 在某一区域内的固定位置,css,position,fixed,Css,Position,Fixed,我正在使用一个侧导航栏,我希望它在屏幕上是一个固定的位置,但我希望它在你向下滚动这么远后停止被固定。有什么办法吗?使用此功能。滚动时,将触发此功能。在函数中写入if条件以删除固定的 $( "#target" ).scroll(function() { if($(element).height() === "500px") { // remove scroll fixed $(scroll).css("position","relative") //or u

我正在使用一个侧导航栏,我希望它在屏幕上是一个固定的位置,但我希望它在你向下滚动这么远后停止被固定。有什么办法吗?

使用此功能。滚动时,将触发此功能。在函数中写入if条件以删除固定的

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

使用此功能。滚动时,将触发此功能。在函数中写入if条件以删除固定的

$( "#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
更改为您想要的值

假设它已经被修复,您只需执行以下操作:

if($(window).scrollTop() > 150){
    $('#nav').css('position', 'relative');
}
当然,将
#nav
更改为您自己的选择器,并将
150
更改为您想要的值