Christian Benseler
Christian Benseler

Reputation: 8075

Ionic: get ionicScroll onScroll event

I found this thread that tells how to get the scroll event of a ionicScroll:

http://forum.ionicframework.com/t/ionicscrolldelegate-doesnt-have-a-onscroll-event/19497

$ionicScrollDelegate.getScrollView().onScroll = function () {
    console.log($ionicScrollDelegate.getScrollPosition());
};

But this doesn't work. The official doc doesn't have anything about this. Any clue?

Upvotes: 3

Views: 13845

Answers (1)

novalain
novalain

Reputation: 2209

If you simply want to listen to to the scroll event maybe the easiest way would be to use the on-scroll directive.

HTML:

<ion-content on-scroll="getScrollPosition()">
    <div class="list">
      <div class="item" ng-repeat="item in data.items">Item {{item}}</div>
    </div>
</ion-content>

JS:

$scope.getScrollPosition = function(){
   console.log($ionicScrollDelegate.getScrollPosition().top)
}

Codepen here

Upvotes: 10

Related Questions