Javascript 滚动至div,但有边距差
使用我的javascript代码,我可以滚动到一个div,但我需要javascript使我比该div高20像素Javascript 滚动至div,但有边距差,javascript,html,margin,pixels,Javascript,Html,Margin,Pixels,使用我的javascript代码,我可以滚动到一个div,但我需要javascript使我比该div高20像素 $(function() { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostna
$(function() {
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
有人能让它比div高出10px吗?多谢各位
这是我的网页,如果你想知道更具体的问题
我的英语不是很好。从
top
$('html,body').animate({
scrollTop: target.offset().top - 10
}, 1000);