2016-01-18 35 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); 
});