点击返回时返回页面顶部

发布于 2024-09-13 00:05:58 字数 411 浏览 4 评论 0原文

我有以下问题:

在此页面上 http://www.projectyou.gr/ gp/?page_id=5 有 3 个选项卡
[全是希腊语,但我希望你能理解]
每个选项卡都包含文章链接。
当您单击一篇文章然后按浏览器上的后退按钮时,它会返回 到选定的选项卡并滚动到您单击的文章。
尽管我很喜欢这种行为,但这并不是我想要的。
我希望用户在返回页面时始终转到顶部。

实现这一目标的最佳方法是什么。
这是否与我使用 jQuery 选项卡和我拥有的代码有关 返回到先前选择的选项卡会导致跳转到先前单击的锚点?

任何帮助将非常感激。
谢谢

I have the following question/problem:

On this page http://www.projectyou.gr/gp/?page_id=5 there are 3 tabs
[It's all in Greek but I hope you will understand]
Each tab contains links to articles.
When you click on an article and then press the back button on the browser it comes back
to the selected tab AND scrolls to the article you clicked.
As much as I like this behavior it is not what I want in this case.
I would like the user, when returning to the page, always go to the top.

What is the best way to achieve this.
Does it have to do with the fact that I'm using jQuery tabs and the code that I have
for returning to the previously selected tab causes to jump to previously clicked anchor??

Any help would be very much appreciated.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅沫记忆 2024-09-20 00:05:58

如何将诸如此类的内容添加到您的文档就绪处理程序中(我意识到您可能已经有一个,因此只需附加scrollTo就可以做到这一点):

$(document).ready(function() {
  window.scrollTo(0, 0);
});

就像这样 所以问题

how about adding something such as this to your document ready handler (I realize you may already have one, so just appending the scrollTo might do it):

$(document).ready(function() {
  window.scrollTo(0, 0);
});

like in this SO question

白况 2024-09-20 00:05:58

您还可以使用

$("html:not(:animated),body:not(:animated)").animate({ scrollTop: 0}, 500 );

以动画方式滚动它,
500 是以毫秒为单位的速度,

0 是从页面顶部开始的距离,

如果你想滚动到某个元素的顶部,你可以将其替换为

var offset = $('element').offset();
var top = offset.top;
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: top}, 500 )

;

You could also use

$("html:not(:animated),body:not(:animated)").animate({ scrollTop: 0}, 500 );

which scrolls it in an animated way,
The 500 is the speed in milliseconds

the 0 is how from from the top of the page,

if you wanted to scroll to the top of an element you could replace it with

var offset = $('element').offset();
var top = offset.top;
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: top}, 500 )

;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文