如何获取和设置当前网页滚动位置? [英] How to get and set the current web page scroll position?
本文介绍了如何获取和设置当前网页滚动位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取并设置当前的网页滚动位置?
我有一个很长的表单,需要根据用户操作/输入进行刷新。当发生这种情况时,页面会重置到最顶端,这对用户来说很烦人,因为他们必须回滚到他们所在的位置。
如果我可以在页面重新加载之前捕捉当前滚动位置(在隐藏的输入中),然后我可以在重新加载之后将其设置回来。 解决方案
p>您正在寻找 document.documentElement.scrollTop
属性。
How can I get and set the current web page scroll position?
I have a long form which needs to be refreshed based on user actions/input. When this happens, the page resets to the very top, which is annoying to the users, because they have to scroll back down to the point they were at.
If I could capture the current scroll position (in a hidden input) before the page reloads, I could then set it back after it reloads.
解决方案
You're looking for the document.documentElement.scrollTop
property.
这篇关于如何获取和设置当前网页滚动位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文