重新加载页面后,如何记住`div`的滚动位置来恢复它? [英] How to remember scroll pos of the `div` to restore it when page is reloaded?

查看:165
本文介绍了重新加载页面后,如何记住`div`的滚动位置来恢复它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的div具有绝对定位

<div style:position: absolute; left:50px; overflow: auto; top:200px; right:100px; bottom:25px;>

上面有徽标等.

但是,如果div向下滚动并刷新页面,则该div的滚动将移到div的顶部.

But if div scrolled down and page is refreshed, the scroll of this div goes at the top of the div.

在刷新页面后,是否有任何方法可以将div保持在以前的位置?

Is there any method to keep div in previous position after page's refresh?

推荐答案

请阅读: 如何使用Javascript获取滚动条位置?

方法1 然后考虑使用滚动条位置存储Cookie.

Method 1 and then consider to store a cookie with the scrollbar position.

方法2 或将值服务器端存储在基于IP的访问者表中

Method 2 or store the value server side in a visitors table on base of the IP

还有另一种有趣的方式.

There is one more funny way.

方法3 使用像<a name="foo">这样的锚点,然后将您的后操作发送到包含像这样的锚点的URL <form action="site.php#foo" ...它不像cookie版本那样精确,但是可以通过某种方式起作用:))

Method 3 use anchors like <a name="foo"> and send your post action to the URL containing the anchor like this <form action="site.php#foo" ... Its not so exact like the cookie version but it works somehow :))

这篇关于重新加载页面后,如何记住`div`的滚动位置来恢复它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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