Search code examples
javascriptjqueryjquery-mobileiscroll4

iScroll4 swipe down and up events


I've written my code as below but when I scroll always onScrollEnd gets fired. How to detect whether user is scrolling down or scrolling up ??

myScroll = new iScroll('SaleListingContainer', { desktopCompatibility: true, useTransition: true,
                        // topOffset: pullDownOffset,
                        onRefresh: function() {
                            alert("refresh");
                        },
                        onScrollMove: function() {
                            alert("move");
                        },
                        onScrollEnd: function() {
                            alert("end");
                        } 
                    });

Thanks for your time and help in advance. Thanks alot.


Solution

  • Use dirY attribute, which is 1 if the user scrolls down or -1 if the user scrolls up:

    onScrollEnd: function() {
                if (this.dirY == 1) { alert('scrolling down'); }
                else if (this.dirY == -1) { alert('scrolling up'); }
    }