javascript Ionic: 获取 ionicScroll onScroll 事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31208804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ionic: get ionicScroll onScroll event
提问by Christian Benseler
I found this thread that tells how to get the scroll event of a ionicScroll:
我发现这个线程告诉如何获取 ionicScroll 的滚动事件:
http://forum.ionicframework.com/t/ionicscrolldelegate-doesnt-have-a-onscroll-event/19497
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?
但这不起作用。官方文档对此没有任何说明。有什么线索吗?
回答by novalain
If you simply want to listen to to the scroll event maybe the easiest way would be to use the on-scroll
directive.
如果您只是想收听滚动事件,那么最简单的方法可能是使用on-scroll
指令。
HTML:
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:
JS:
$scope.getScrollPosition = function(){
console.log($ionicScrollDelegate.getScrollPosition().top)
}
Codepen here
代码笔在这里