【问题标题】:Bootstrap Affix fixed header after 100px making content jumpBootstrap Affix 100px 后的固定标题使内容跳转
【发布时间】:2018-08-18 00:09:07
【问题描述】:

我在我的标题上使用了 Bootstrap Affix,我希望它在页面滚动 100 像素后得到修复。我在jquery中添加了这样的:

$('#navbar').affix({
      offset: {
        top: 100,
      }
    });

问题是当我滚动页面上的内容时会跳起来。我添加了一个最小高度的包装器,但这并不能解决问题。

有人可以帮忙吗?

小提琴链接: https://jsfiddle.net/b5fusmsn/12/

【问题讨论】:

  • data-spy="affix" 添加到navbarpadding-topcontent

标签: jquery css twitter-bootstrap affix


【解决方案1】:

闪烁/跳跃是因为导航栏从position:static 更改为postition:fixed。当在 100px 处应用词缀时,接近导航栏 92px 的高度,除非您有 div of 100px in height above the navbar like in this question,否则它总是会“跳跃”。

在您的情况下,您似乎只是在滚动 100 像素后试图缩小导航栏填充,因此在这种情况下,请始终保持导航栏位置:固定,并在应用 .affix 时调整填充...

https://jsfiddle.net/etxyk0y1/1/

.navbar {
    min-height: 50px;
    z-index: 99998;
    background:red;
    width:100%;
    position: fixed;
    transition: all .5s;
    top: 0;
}

.affix-top.navbar {
    padding-bottom: 20px;
    border: 1px solid transparent;
    padding-top: 20px;
}

.affix.navbar {
    padding-top: 10px;
    padding-bottom: 10px;
    font-size: 0.9em;
    border-bottom: 1px solid #f9f7f3;
    transition: all .5s;
}

使用nav-wrapper 保持固定导航栏和内容之间的间距。

.nav-wrapper {
    padding-top: 100px;
}

【讨论】:

  • 请接受此答案,以便其他人知道此问题已解决。
猜你喜欢
  • 1970-01-01
  • 2023-03-22
  • 1970-01-01
  • 1970-01-01
  • 2014-10-06
  • 2015-04-05
  • 2017-11-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多