Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 引导添加带有scrollspy和固定导航的偏移量_Css_Twitter Bootstrap_Navigation_Smooth Scrolling - Fatal编程技术网

Css 引导添加带有scrollspy和固定导航的偏移量

Css 引导添加带有scrollspy和固定导航的偏移量,css,twitter-bootstrap,navigation,smooth-scrolling,Css,Twitter Bootstrap,Navigation,Smooth Scrolling,我已使用scrollspy和平滑滚动设置了固定导航: HTML 这工作得很好,不幸的是它滚动时没有任何偏移(我的导航高度为80px)。我试图添加“数据偏移量=80”,但这没有任何作用。我不太确定我必须向JS添加什么才能使其正常工作:(由于您有一个导航栏固定顶部,您需要手动设置偏移量。请尝试 $("body").scrollspy({offset: 80}); 的答案可能会对您有所帮助。请使用css技巧尝试本教程,无javascript: $(".navbar-nav li a[href^='#

我已使用scrollspy和平滑滚动设置了固定导航:

HTML


这工作得很好,不幸的是它滚动时没有任何偏移(我的导航高度为80px)。我试图添加“数据偏移量=80”,但这没有任何作用。我不太确定我必须向JS添加什么才能使其正常工作:(

由于您有一个导航栏固定顶部,您需要手动设置偏移量。请尝试

$("body").scrollspy({offset: 80});

的答案可能会对您有所帮助。请使用css技巧尝试本教程,无javascript:
$(".navbar-nav li a[href^='#']").on('click', function(e) {
e.preventDefault();

var hash = this.hash;
$('html, body').animate({
   scrollTop: $(this.hash).offset().top
 }, 1000, function(){
   window.location.hash = hash;
 });

}); 
$("body").scrollspy({offset: 80});