[英]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'});
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.