重新加载页面时保持滚动条位置 [英] Maintain scrollbar position upon page reload

查看:236
本文介绍了重新加载页面时保持滚动条位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让表内容转到刷新页面之前的位置,而不是转到表内容的顶部.换句话说,如果用户向下滚动,并且按钮触发页面重新加载,则我希望表内容在刷新后返回到相同位置.

I would like to have the table content to go to the same position that it had before the page is refreshed rather than go to the top of the table content. In other words, if the user scrolls down, and a button triggers a page reload, I want table content to come back to the same position after the refresh.

用于我的表格的CSS是

CSS used for my table is

#invoice_incomplete {width:850px;height:400px;overflow:auto;}

推荐答案

您可以使用Javascript实现此目的.在页面加载时,您可以编写[如果表格有滚动条]

You can achieve this using Javascript. On page load you can write [if table has scroll bar]

document.getElementById("invoice_incomplete").scrollTop = 200px; // where you want scroll

或整个页面写

 document.body.scrollTop = 200px; // 

这篇关于重新加载页面时保持滚动条位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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