Get scroll direction


#1

Is it possible to get the scroll direction in ion-content? I need to use different behaviours depending if the user is scrolling to top or to bottom.

thanks


#2

See my sample in this post :

Just create a directive that detects the difference in the elements scrollTop


#3

Thanks,

already solved in a similar way:


myapp.directive('scrolling', function($document) {
  return {
    restrict: 'A',
    link: function(scope, element, attrs) {
      var start = scope.$eval(attrs.scrolling) || 0;

      element.bind('scroll', function(e) {
        if(e.detail.scrollTop >= start) {
          start = e.detail.scrollTop;
          console.log('scroll to bottom');
        } else {
          console.log('scroll to top');
        }
      });
    }
  }
});


#4

I just moved the line : start = e.detail.scrollTop;

right after the else statement.

Otherwise, the directive doesn’t work anymore as soon as you reach the bottom of the scroll range.


#5

I tried the code suggested on this page, but when I reach the bottom the bug is still there. Did you ever manage to figure this out?


#6

Great, but e.detail does not exist in android platform


#7

Struggling with the same thing now, did you manage to find a workaround?


#8

if you are referring to Android issue, this code snippet will fix it

app.config(function($ionicConfigProvider) { if(ionic.Platform.isAndroid()){ $ionicConfigProvider.scrolling.jsScrolling(true); } });


#9

Yes, that is what I was referring to. Thanks! So basically I need to revert to pre-1.2 JS scrolling for this to work.