Ionic: get ionicScroll onScroll event
13,630
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
Author by
Christian Benseler
Updated on June 30, 2022Comments
-
Christian Benseler almost 2 years
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?
-
Christian Benseler almost 9 yearsFor some reason, this code does not work in my app. I think I have something else "blocking" it. I found a blog post which tells to use the on-refresh directive to call a function that broadcast scroll.refreshComplete event (with $scope.$broadcast('scroll.refreshComplete');) and now it works. Thanks.
-
Meliodas about 7 yearsHow to approach this problem if I want to listen to scroll event from a directive? any help?