当用户在Ionic 2上滚动时拾起我很困惑.我基本上想说,当用户向下滚动页面时,做一些事情.
任何例子都会很棒.
更新:
我在我的构造函数中有这个,所以当页面滚动时我想要关闭键盘,因为它是打开的,没有其他方法可以关闭.
import { Component,ViewChild } from '@angular/core'; import { NavController,NavParams,Content } from 'ionic-angular'; import { Keyboard } from '@ionic-native/keyboard'; export class SearchPage { @ViewChild(Content) content:Content; constructor(public keyboard: Keyboard,public formBuilder: FormBuilder,public navCtrl: NavController,public navParams: NavParams,public apiAuthentication: ApiAuthentication,private http: Http) { this.content.ionScroll.subscribe((data)=>{ this.keyboard.close(); }); } }
您可以订阅内容事件.
> ionScroll在每个滚动事件上发出.
> ionScrollEnd滚动结束时发出.
> ionScrollStart首次滚动时发出.
听一个事件:
@ViewChild(Content) content: Content; // ... ngAfterViewInit() { this.content.ionScrollEnd.subscribe((data)=>{ //... do things }); }
或者从DOM做到:
<ion-content (ionScroll)="onScroll($event)">
对于Ionic 4
<ion-content [scrollEvents]="true" (ionScroll)="onScroll($event)">