具有平滑滚动的固定标题的帐户

我有一个jQuery脚本使用我的网站上的一些平滑滚动,我有一个固定的位置标题,但我不知道如何考虑固定标题大小,因为当它向下滚动时,固定标题覆盖标题。

$(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; } } }); }); 

有人有什么建议吗?

您需要通过从移动视图的位置减去固定标题的高度来适应它。

 $('html, body').animate({ scrollTop: target.offset().top - fixedHeader.outerHeight() }, 1000); 

只需将“fixedHeader”替换为您用于固定标头的任何元素。

这是一个HTML和CSS创建固定标头: