gpt4 book ai didi

ionic2 - ionic 2滚动事件

转载 作者:行者123 更新时间:2023-12-01 12:28:21 26 4
gpt4 key购买 nike

我有一个 ionic 滚动组件。我试图在滚动期间执行一些代码。在 Ionic 1 中,这可以使用 on-scroll 属性并传递一个函数。

文档也丢失了。 Ionic 2 中是否有检测滚动的内置方法,或者我是否必须退回到使用 jQuery 或窗口滚动事件添加我自己的事件处理程序?

最佳答案

您可以使用 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>

您的 typescript :

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);
}
}

关于ionic2 - ionic 2滚动事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37235949/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com