无论如何使用scrollTop但保留主题标签?

我正在使用以下代码:

$('#toc a').on('click', function(e) { e.preventDefault(); $link = $(this).attr('href'); $('html, body').animate({ scrollTop: $($link).offset().top - 10 }, 1000 );  }); 

但是希望它保留url中链接的#标签。 这可能与代码有关吗? 谢谢

 $('#toc a').on('click', function(e) { $link = $(this).attr('href'); $('html, body').animate({ scrollTop: $($link).offset().top - 10 }, 1000 ); });