离子2滚动事件

时间:2016-05-15 08:14:02

标签: ionic2

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

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

3 个答案:

答案 0 :(得分:2)

我在这里找到了一个解决方案:“On-scroll” not working in

使用"addScrollEventListener"内的"ngAfterViewChecked"

答案 1 :(得分:2)

您可以使用Scroll组件的Before - { title: 'im mr meeseeks', link: null, _id: 589f0f3ddf781803b459dc00, comments: [], upvotes: 2 } After - { author: 'Meseeks', title: 'im mr meeseeks', link: null, _id: 589f0f3ddf781803b459dc00, comments: [], upvotes: 2 } Creating author Pre validate document printing - { author: 'Meseeks', title: 'im mr meeseeks', link: null, _id: 589f0f3ddf781803b459dc00, comments: [], upvotes: 2 } Pre validate called. Title : 589f0f3ddf781803b459dc00 Author is : Meseeks hasOwnProperty : false this.author=='' : false Here Post validate called. Title : 589f0f3ddf781803b459dc00 Pre save called. Title : 589f0f3ddf781803b459dc00 Post save called. Title : 589f0f3ddf781803b459dc00 方法,如下所示:

addScrollEventListener

您的HTML:

this.scroll.addScrollEventListener((event) => {
    console.log(event);
});

你的打字稿:

<ion-header>
    <ion-navbar>
        <ion-title>Title</ion-title>
    </ion-navbar>
</ion-header>

<ion-content class="no-scroll">
    <ion-scroll></ion-scroll>
</ion-content>

答案 2 :(得分:0)

我从这里找到了这个解决方案:https://forum.ionicframework.com/t/ionic-2-rc4-addscrolllistener/73145/16?u=kamleshappster

this.content.ionScroll.subscribe(($event) => {
 this.scrollAmount = $event.scrollTop;
});