Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

Infinite Scroll

I've followed the tutorial on here but i cant get it to work.
https://blog.appery.io/2015/07/how-to...

my JS asset is:
pre
var onScrollHandler = function(){

window.clearTimeout(self.scrollTimeout);

var onDelay = function(){
var scrollTop = jQuery(window).scrollTop();
var windowHeight = jQuery(window).height();
var scrollHeight = jQuery(document).height();
var scrollBottom = scrollHeight - scrollTop - windowHeight;

Code: Select all

console.log("scrollBottom = " + scrollBottom); 

if(scrollBottom < 50) 
   jQuery(window)&#46;trigger("onScrollBottom"); 
}; 
self&#46;scrollTimeout = window&#46;setTimeout(onDelay, 500); 

};

$(function() {
jQuery(window)&#46;scroll(onScrollHandler);
});
/pre

JS on page load:
pre
var onScrollBottom = function(){

Code: Select all

 var infiniteList = Apperyio&#46;storage&#46;homeInfinite&#46;get(); 

 if(infiniteList&#46;noMoreItems == "true") 
    return;         

 infiniteList&#46;skip = parseInt(infiniteList&#46;skip) + parseInt(infiniteList&#46;limit) + ""; 
 Apperyio&#46;storage&#46;homeInfinite&#46;set(infiniteList); 
 listReviews&#46;execute(); 

};

jQuery(window)&#46;bind("onScrollBottom", onScrollBottom);
/pre

JS on page show:
pre

$(function() {
jQuery(window)&#46;scroll(onScrollHandler);
});

&#47;&#47;Here you can set the needed "limit"&#46; Currently it's set to 12&#46;
var infiniteList = {limit: "5", skip: "0", noMoreItems: undefined};
Apperyio&#46;storage&#46;homeInfinite&#46;set(infiniteList);
jQuery( window )&#46;scroll(onScrollHandler);
/pre

I also invoke listReviews service on page show.

on service success JS (but before the mapping):
pre
self&#46;homeScrollTop = jQuery(window)&#46;scrollTop();

if(data&#46;length == 0){
var infiniteList = Apperyio&#46;storage&#46;homeInfinite&#46;get();
infiniteList&#46;noMoreItems = "true";

Code: Select all

 Apperyio&#46;storage&#46;homeInfinite&#46;set(infiniteList); 

};

&#47;&#47;Where "infinite_list" is your list component name&#46;
self&#46;homeListItems = Apperyio("postList_home")&#46;find("li:not([data-appery-tpl])");

homeListItems&#46;detach();
/pre

on service success JS (after mapping):
pre
&#47;&#47;Where "infinite_list" is your list component name&#46;
Apperyio("postList_home")&#46;prepend(self&#46;homeListItems);
jQuery(window)&#46;scrollTop(self&#46;homeScrollTop);
/pre

The limit and skip is set on page show and the service is invoked according to the limit. but when i scroll to the bottom nothing happens.

I had a look at the demo...
http://infinitescroll.app.appery.io/s...
... and every time i scroll here the scrollBottom is shown in the console log.

But when I scroll on my app the scrollBottom is not shown in the console.log. suggesting that the scroll function is not being recognised.

any suggestions?

thank you

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Infinite Scroll

Hello,
We are very sorry, but debug your custom code is something outside the scope (https://docs.appery.io/docs/general-s...) of our standard support.

Please check if there are any errors in the browser console. You can learn here: https://docs.appery.io/docs/using-bro... how to open the console.

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

Infinite Scroll

But it's not really custom code, the only changes to the code from the tutorial is the name of the service and the storage variable.

Ok, I have deleted all the code above and replaced it with the exact same code in the tutorial. but instead i have changed the storage variable and service name to match the tutorial... is there anything you can do to help now?

I'm receiving no errors in my console

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

Infinite Scroll

This isn't really custom code- it's the code in the tutorial with only service names and local storage names changed.

Either way i have isolated the problem...

Replace the JS on page show:

jQuery(window).scroll(onScrollHandler);

with:

window.setTimeout( function(){
jQuery(window).scroll(onScrollHandler);
},100);

I suggest you change this on the tutorial so that others don't encounter the same problem.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Infinite Scroll

Thank you for update! Glad to hear things are sorted out now!

Return to “Issues”