回到上一页

时间:2016-05-06 05:33:34

标签: javascript jquery

假设我在我的索引页面上向下滚动到我<div>的18/50,然后我转到同一标签中的另一个页面并返回上一页。

如何在<div>的18/50上向下滚动到同一位置?

scroll.js

var ajax_arry = [];
var ajax_index = 0;
var sctp = 100;
$(function () {
    $('#loading').show();
    $.ajax({
        url: "scroll.php",
        type: "POST",
        data: "actionfunction=showData&page=1",
        cache: false,
        success: function (response) {
            $('#loading').hide();
            $('#demoajax').html(response);

        }

    });
    $(window).scroll(function () {

        var height = $('#demoajax').height();
        var scroll_top = $(this).scrollTop();
        if (ajax_arry.length > 0) {
            $('#loading').hide();
            for (var i = 0; i < ajax_arry.length; i++) {
                ajax_arry[i].abort();
            }
        }
        var page = $('#demoajax').find('.nextpage').val();
        var isload = $('#demoajax').find('.isload').val();

        if ((($(window).scrollTop() + document.body.clientHeight) == $(window).height()) && isload == 'true') {
            $('#loading').show();
            var ajaxreq = $.ajax({
                url: "scroll.php",
                type: "POST",
                data: "actionfunction=showData&page=" + page,
                cache: false,
                success: function (response) {
                    $('#demoajax').find('.nextpage').remove();
                    $('#demoajax').find('.isload').remove();
                    $('#loading').hide();

                    $('#demoajax').append(response);

                }

            });
            ajax_arry[ajax_index++] = ajaxreq;

        }
        return false;

        if ($(window).scrollTop() == $(window).height()) {
            alert("bottom!");
        }
    });

});

1 个答案:

答案 0 :(得分:1)

将窗口偏移顶部存储在localstorage

var windowscrolltop = localStorage.getItem('windowscrolltop');
  $('html, body').animate({
    scrollTop: windowscrolltop
}, 500);

当你回到页面时,绑定完成了对该点的动画。

{{1}}