2016-01-18 37 views
-3

我有一个固定的标题,使标题后面有少量div。所以我想滚动到#services div但-100px滚动和下面的代码是我目前使用的。我怎么会去在下面的代码行中减去100px如何根据我们的需要滚动

$(".menu-services").click(function() { 
    $('html, body').animate({ 
     scrollTop: $("#services").offset().top 
    }, 2000); 
}); 
+4

所以你问的是如何减去100? –

回答

2

使用下面的代码:

$(".menu-services").click(function() { 
    $('html, body').animate({ 
     scrollTop: $("#services").offset().top - 100 
    }, 2000); 
}); 

,并使其更有活力,让我们说你的头ID为fixed-header那么你可以这样写:

$(".menu-services").click(function() { 
    $('html, body').animate({ 
     scrollTop: $("#services").offset().top - $('#fixed-header').outerHeight() 
    }, 2000); 
});