Ionic2 离子2滚动事件
我有一个离子滚动组件。 我试图在滚动期间执行一些代码。在Ionic 1中,可以使用on scroll属性并传递函数 文件也不见了。Ionic 2中是否有内置的检测滚动的方法,或者我是否必须使用jQuery或window scroll event添加自己的事件处理程序?我在这里找到了一个解决方案:Ionic2 离子2滚动事件,ionic2,Ionic2,我有一个离子滚动组件。 我试图在滚动期间执行一些代码。在Ionic 1中,可以使用on scroll属性并传递函数 文件也不见了。Ionic 2中是否有内置的检测滚动的方法,或者我是否必须使用jQuery或window scroll event添加自己的事件处理程序?我在这里找到了一个解决方案: 使用“addScrollEventListener”内部“nAfterViewChecked”可以使用Scroll组件的addScrollEventListener方法,如下所示: this.scrol
使用
“addScrollEventListener”
内部“nAfterViewChecked”
可以使用Scroll组件的addScrollEventListener
方法,如下所示:
this.scroll.addScrollEventListener((event) => {
console.log(event);
});
您的HTML:
<ion-header>
<ion-navbar>
<ion-title>Title</ion-title>
</ion-navbar>
</ion-header>
<ion-content class="no-scroll">
<ion-scroll></ion-scroll>
</ion-content>
import {Component, ViewChild} from '@angular/core';
import {Scroll} from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
@ViewChild(Scroll) scroll: Scroll;
constructor() {}
ngAfterViewInit() {
this.scroll.addScrollEventListener(this.onScroll);
}
onScroll(event) {
console.log(event);
}
}
我从这里找到了这个解决方案:
当前解决方案您好,如何侦听ion scroll的ScrollStart和scrollEnd事件?这是最佳解决方案:
this.content.ionScroll.subscribe(($event) => {
this.scrollAmount = $event.scrollTop;
});