0
我想调整滚动时使用锚点的位置,因为我使用粘滞标题和锚点位置似乎基于自身的顶部即使我在主页div上有css padding,这个页面本身可以工作,但是当我点击一个锚点时,它不能正常工作。使用jquery调整锚定目标的位置,以考虑粘滞标题
我把这个平滑滚动码只要锚链接从页面本身来,但它没有任何效果,当我从另一个页面
$('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 - 120)
}, 1000);
return false;
}
}
});
直接导航到锚的正常工作
任何人都可以帮助我得到这个工作,所以它是相同的,无论点击来自另一个页面或锚内的页面。