【问题标题】:Fixed Position in a certain area CSS固定位置在某个区域 CSS
【发布时间】:2015-07-03 08:09:24
【问题描述】:

我正在使用侧面导航栏,我希望它成为屏幕上的固定位置,但我希望它在您向下滚动这么远后停止固定。有没有办法解决这个问题?

【问题讨论】:

    标签: css position fixed


    【解决方案1】:

    使用此功能。滚动时将触发此功能。在函数内部编写 if 条件以删除固定

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

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 2018-01-01
        • 2019-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-16
        • 2020-05-18
        • 2011-06-25
        相关资源
        最近更新 更多