Bootstrap 固定 header 后 100px 使内容跳转
Bootstrap Affix fixed header after 100px making content jump
我在 header 上使用 Bootstrap Affix,我希望它在页面滚动 100 像素后固定。我在 jquery 中添加了这样的内容:
$('#navbar').affix({
offset: {
top: 100,
}
});
问题是当我滚动页面上的内容时会跳起来。我添加了一个最小高度的包装纸,但这并不能解决问题。
有人可以帮忙吗?
Link 到 fiddle:
https://jsfiddle.net/b5fusmsn/12/
flicker/jump 是因为导航栏从 position:static
变为 postition:fixed
。当词缀应用到 100px 时,接近导航栏 92px 的高度,除非你有 div of 100px in height above the navbar like in this question.
,否则它总是会 "jump"
在你的情况下,看起来你只是想在滚动 100px 后缩小导航栏填充,所以在这种情况下始终保持导航栏 postion:fixed 并在 .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;
}
我在 header 上使用 Bootstrap Affix,我希望它在页面滚动 100 像素后固定。我在 jquery 中添加了这样的内容:
$('#navbar').affix({
offset: {
top: 100,
}
});
问题是当我滚动页面上的内容时会跳起来。我添加了一个最小高度的包装纸,但这并不能解决问题。
有人可以帮忙吗?
Link 到 fiddle: https://jsfiddle.net/b5fusmsn/12/
flicker/jump 是因为导航栏从 position:static
变为 postition:fixed
。当词缀应用到 100px 时,接近导航栏 92px 的高度,除非你有 div of 100px in height above the navbar like in this question.
在你的情况下,看起来你只是想在滚动 100px 后缩小导航栏填充,所以在这种情况下始终保持导航栏 postion:fixed 并在 .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;
}