强制页面滚动位置在页面刷新页面顶部 [英] Force page scroll position to top at page refresh in HTML

查看:159
本文介绍了强制页面滚动位置在页面刷新页面顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个我用 div s发布的网站。当我在页面滚动到位置X后刷新页面时,页面将以滚动位置加载为X.



如何强制页面滚动到在页面刷新顶部?




  • 我能想到的是一些JS或jQuery运行为 onLoad()页面的功能 SET 页面滚动到顶部。但是我不知道我该怎么做。

  • 如果有一些属性或某些东西让页面加载了滚动条,那么更好的选择是位置作为默认值(即位于顶部),这将有点像页面加载,而不是页面刷新



解决方案

您可以使用准备好DOM :noreferrer> scrollTop 方法:

  $(document).ready(function(){
$(this).scrollTop(0);
});


I am building a website which I am publishing with divs. When I refresh the page after it was scrolled to position X, then the page is loaded with the scroll position as X.

How can I force the page to be scrolled to the top on page refresh?

  • What I can think of is of some JS or jQuery run as onLoad() function of the page to SET the pages scroll to top. But I don't know how I could do that.

  • A better option would be if there is some property or something to have the page loaded with its scroll position as default (i.e. at the top) which will be kind of like page load, instead of page refresh.

解决方案

You can do it using the scrollTop method on DOM ready:

$(document).ready(function(){
    $(this).scrollTop(0);
});

这篇关于强制页面滚动位置在页面刷新页面顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆