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

Javascript 使用mCustomScrollbar jquery刷新后滚动到顶部如何防止,javascript,jquery,css,Javascript,Jquery,Css,拖动滚动设置为滚动,以便用户可以滚动,但当刷新发生时,滚动返回顶部。在页面刷新后如何保持滚动位置 {literal} (function($){ $(window).load(function(){ /* custom scrollbar fn call */ $(".content_2").mCustomScrollbar({ scrollInert

拖动滚动设置为滚动,以便用户可以滚动,但当刷新发生时,滚动返回顶部。在页面刷新后如何保持滚动位置

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

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

您可以在此处看到图像

在本地存储中设置图像,并在窗口加载时检索图像:

$(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());
});

演示

有很多方法可以做到这一点,首先显示HTML,或者制作一个提琴。您的代码在systmen scroller上运行良好,但我使用的是McCustomScrollbar jquery,它不起作用