简体   繁体   English

Bootstrap-滚动时的粘性/固定导航栏

[英]Bootstrap - sticky/fixed navbar when scroll

I'd like to create a navbar like this one: http://bartiistudio.tk/noxilie/onepage/index.html 我想创建一个像这样的导航栏: http : //bartiistudio.tk/noxilie/onepage/index.html

Well, I use stickUp jQuery script but my navbar doesn't work Wery well. 好吧,我使用stickUp jQuery脚本,但是导航栏无法正常工作。 I don't know how to fix it. 我不知道该如何解决。

And here is jsfiddle: http://jsfiddle.net/52VtD/792/ 这是jsfiddle: http : //jsfiddle.net/52VtD/792/

stickUp code: stickUp代码:

jQuery(function($) {
        $(document).ready( function() {
         //enabling stickUp on the '.navbar-wrapper' class
         $('.navbar-wrapper').stickUp();
         });
});

If all your problem is the navbar-wrapper not occupying the full width. 如果您所有的问题是navbar-wrapper没有占据整个宽度。 You just need to set it width:100% . 您只需要设置width:100% The stickUp changed the position of the navbar from relative to fixed so that caused the problem. stickUp将导航栏的位置从relative更改为fixed从而引起了问题。

If all you need to do is just stick the navbar on top why not create your own script. 如果您需要做的只是将导航栏放在最上面,那为什么不创建自己的脚本。

It's fun and easy :D 好玩又容易:D

$(document).ready( function() {
    var $stick = $('.navbar-wrapper');

    $(window).scroll(function(){
        var scrollTop = $(this).scrollTop();

        if(scrollTop >= $stick.offset().top){
            $stick.css({'position':'fixed'});
        }else{
            $stick.css({'position':'relative'});
        }
    });
});

See this jsfiddle 看到这个jsfiddle

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

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