1

我有一个 jQuery 选项卡元素,其中每个选项卡都向 URL 添加一个哈希,如下所示:

www.mysite.com/services#one
www.mysite.com/services#two
www.mysite.com/services#three

我想阻止滚动到该元素(选项卡)的默认浏览器行为,我可以使用 preventDefault 来做到这一点。

但我还想保持链接到已打开特定选项卡的页面的能力。因此,如果我访问 www.mysite.com/services#three,它应该会将我带到打开第三个选项卡的那个页面,但它不应该滚动到页面中的那个位置。

可能的?

4

2 回答 2

0

不完全可能,但您可以在基于片段加载页面后打开选项卡:

//bind click events above

//assumes that ID of tab is the same as the fragment
$(window.location.hash).click();

//scroll to the top, if you really want/need to:
$(window).scrollTop(0);
于 2012-12-05T21:37:32.940 回答
0

一个解决方案可能是。

$(document).ready(function() {
  $.scrollTo('0px');
});

资源

于 2012-12-05T21:39:09.373 回答