I have a full AJAX website. On a page with 12 elements and a homemade infinite scroll (just a "more" link at the bottom of the page, loading the 12 next elements), when I click on one of these links, it loads the page.
The problem
When I want to come back to the list (browser's previous or close link) and if I loaded more than 12 photos (all, for example), I lose the loaded elements and I need to scroll to the bottom of the page… load another elements… click on it… load the page… go back, etc.
Do you know what can I do to avoid this behavior and keep the loaded elements progression?
My test
I tested something. I define a variable with the base loaded elements and I compare it with the new loaded elements, then it runs something if the last
value is higher than the new one.
last = $(".grid.photos article").length;
var newelems = $(data).find(".grid.photos article").length,
perpage = 12,
diff = last - newelems;
if (last > newelems){
var times = Math.ceil(diff / perpage);
// DO SOMETHING MAGIC
}