简体   繁体   English

Bootstrap affix()插件在滚动内容时出现问题

[英]Bootstrap affix() plugin having issue while scrolling the content

I'm trying to use the Bootstrap affix() plugin. 我正在尝试使用Bootstrap affix()插件。 I want the navbar to pin to the top of the screen when I scroll. 滚动时,我希望导航栏固定在屏幕顶部。 here is what i have so far: http://jsfiddle.net/zncud7md/2/ 这是我到目前为止所拥有的: http : //jsfiddle.net/zncud7md/2/

The issue is the content below navbar shifts (tiny bit of inch downwards) when the affix class triggers in. I even tried adding the: #header.affix + #body { padding-top: 75px; } 问题是当词缀类触发时,导航栏下面的内容(向下移动了#header.affix + #body { padding-top: 75px; }英寸)。我什至尝试添加以下内容: #header.affix + #body { padding-top: 75px; } #header.affix + #body { padding-top: 75px; } that i found on other sources but didnt work for me. #header.affix + #body { padding-top: 75px; } ,我在其他来源上找到了,但对我没有用。 I'm unable to find a way around this. 我找不到解决此问题的方法。 Any ideas how can i prevent this issue?? 任何想法,我怎么能防止这个问题? Thanks!! 谢谢!!

Bootstrap affix acts like sticky positioning so that if you scroll, you can have an element stick to a fixed position ( http://getbootstrap.com/javascript/#affix ). Bootstrap词缀的作用类似于粘性定位,因此,如果滚动,则可以将元素粘贴到固定位置( http://getbootstrap.com/javascript/#affix )。

Instead, you can simplify your code by setting your header position to fixed at top:0 and pad the top of your body. 相反,您可以通过将标头位置设置为固定在top:0并填充身体的顶部来简化代码。

#header {
    position: fixed;
    top: 0;
    z-index: 9999;
}
#body {
    padding-top: 75px;
}

http://jsfiddle.net/zncud7md/4/ http://jsfiddle.net/zncud7md/4/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM