Reputation: 475
Suppose I scrolling down to the 18/50 of my <div>
on my Index page then I go to another page in the same tab and go back to previous page.
How do I make a scroll down to the same position on 18/50 of my <div>
?
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!");
}
});
});
Upvotes: 2
Views: 1373
Reputation: 403
store the window offset top in localstorage
localStorage.setItem('windowscrolltop',$(window).scrollTop());
and when u came back to the page and binding done animate to that point.
var windowscrolltop = localStorage.getItem('windowscrolltop');
$('html, body').animate({
scrollTop: windowscrolltop
}, 500);
Upvotes: 1