【发布时间】:2016-11-02 05:47:16
【问题描述】:
我正在使用CSS Tricks Smooth Scrolling 使我的菜单链接滚动到页面的不同部分。我添加了- jQuery('#masthead').height() 来说明固定导航栏的高度。但是,当我单击一个菜单项并且页面滚动到该点时,菜单栏和它滚动到的位置之间似乎有一个额外的像素。 See what I mean here.
这是我的 jQuery 代码:
jQuery(function() {
jQuery('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = jQuery(this.hash);
target = target.length ? target : jQuery('[name=' + this.hash.slice(1) +']');
if (target.length) {
jQuery('html, body').animate({
scrollTop: target.offset().top - jQuery('#masthead').innerHeight()
}, 1000);
return false;
}
}
});
});
【问题讨论】:
-
对我来说很好......
标签: jquery