无论如何要使用scrollTop但保留主题标签? [英] Anyway to use scrollTop but retain the hashtag?
本文介绍了无论如何要使用scrollTop但保留主题标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码:
$('#toc a').on('click', function(e) {
e.preventDefault();
$link = $(this).attr('href');
$('html, body').animate({
scrollTop: $($link).offset().top - 10
}, 1000 );
});
但是,它希望保留网址中链接的主题标签.代码有可能吗?谢谢
But would like it to keep the hashtag from the link in the web address. Is this possible with the code? Thanks
推荐答案
$('#toc a').on('click', function(e) {
$link = $(this).attr('href');
$('html, body').animate({
scrollTop: $($link).offset().top - 10
}, 1000 );
});
这篇关于无论如何要使用scrollTop但保留主题标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文