【发布时间】:2021-04-04 23:18:34
【问题描述】:
出现了一些问题,导致滚动“contents_container”而不是滚动“body”。
从此以后,点击“history.back”忘记滚动位置。
我找到了 jquery cookie,但它不起作用。
// When document is ready...
$(document).ready(function() {
// If cookie is set, scroll to the position saved in the cookie.
if ( $.cookie("scroll") !== null ) {
$(document).scrollTop( $.cookie("scroll") );
}
// When a button is clicked...
$('#submit').on("click", function() {
// Set a cookie that holds the scroll position.
$.cookie("scroll", $(document).scrollTop() );
});
});
还有这个。
if (history.scrollRestoration === 'manual') {
history.scrollRestoration = 'auto';
}
还有this。
我真的很想记住页面的滚动位置。
这是我的 css 代码,你能解决这个问题吗?
.contents_container {width: 100%; height: 100%; overflow-y: scroll; position: relative; float:left;}
谢谢。
【问题讨论】:
-
谢谢你,但它不起作用。
-
你介意localStorage吗?
-
@sergeykuznetsov 你能解释一下吗?
-
您的 snipped 代码存在一个问题,您没有将值从 cookie 解析为数字。
标签: javascript html jquery css