gpt4 book ai didi

javascript - 使用 mCustomScrollbar jquery 刷新后滚动到顶部如何防止它

转载 作者:太空宇宙 更新时间:2023-11-04 03:56:51 24 4
gpt4 key购买 nike

拖动滚动设置为滚动以便用户可以滚动,但是当刷新发生时滚动回到顶部。有什么想法可以在刷新页面后保持滚动位置吗?

{literal}
(function($){
$(window).load(function(){
/* custom scrollbar fn call */

$(".content_2").mCustomScrollbar({
scrollInertia:150;,
theme:"light";
});
});
})(jQuery);
{/literal}

你可以在这里看到图片enter image description here

最佳答案

将其设置在本地存储中并在窗口加载时检索它:

$(window).load(function () {
// load custom scrollbar here...
var _top = localStorage.getItem('scrollPosition') || 0;
$('html, body').scrollTop(_top);
});

$(window).on('scroll', function (e) {
localStorage.setItem('scrollPosition', $(this).scrollTop());
});

演示:http://jsfiddle.net/G5uFr/

关于javascript - 使用 mCustomScrollbar jquery 刷新后滚动到顶部如何防止它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22679688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com