简体   繁体   English

刷新页面不刷新滚动条JavaScript

[英]refresh page doesn't refresh scroller javascript

When I refresh the page, the javascripts (scrollers) do not refresh as they stay in the same position that they started. 当我刷新页面时,javascript(滚动条)不会刷新,因为它们停留在与开始时相同的位置。 What code do I need to implement into each javascript that will allow the scroller to refresh at the same time the page refreshes? 我需要在每个javascript中实现哪些代码,以允许滚动条在页面刷新的同时刷新?

I saw this: 我看见了这个:

window.location.reload(true);

but this didn't work. 但这没用。

JS JS

Here is my JS: 这是我的JS:

$(function () {  // DOM READY shorthand

    $("#right, #left").click(function () {
        var dir = this.id == "right" ? '+=' : '-=';
        $(".outerwrapper").stop(false,true).animate({ scrollLeft: dir + '251' }, 1000);
    });

});

And I have this at the top: 我在顶部有这个:

$(document).ready(function () {
    $(this).scrollTop(0);
});

Try with the following just before reloading the page. 重新加载页面之前,请尝试以下操作。

$('body').scrollTop(0);

EDIT: The above solution is scrolling vertically while I think you want to scroll horizontally. 编辑:以上解决方案是垂直滚动,而我认为您想水平滚动。

I've looked at the code you added, try the following: 我查看了您添加的代码,请尝试以下操作:

$(".outerwrapper").scrollLeft(0)...

try this 尝试这个

 window.scrollTo(0, 0);

this will scroll to the top left corner of the window. 这将滚动到窗口的左上角。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM