我正在使用JavaScript在我的网站上实现平滑滚动,我遇到了CSS scroll-margin-top导致结尾跳转的问题.我使用以下css来实现滚动页边距:
class or div {
scroll-margin-top: 6rem;/*any size*/
}
我也有一个流畅的滚动脚本功能.问题是,当滚动到这些部分时,当到达滚动的末尾时,会出现明显的 skip .
以下是该脚本的代码:
var ssSmoothScroll = function () {
$('a[href^="#"], area[href^="#"]').on('click', function (e) {
var target = $($(this).attr('href'));
if (target.length) {
e.preventDefault();
$('html, body').stop().animate({
scrollTop: target.offset().top
}, cfg.scrollDuration, 'swing', function () {
window.location.hash = target.attr('id');
});
}
});
};
如何才能在不跳转的情况下解决这个问题并保持流畅的滚动?