【问题标题】:Event "ionScroll" in ion-scroll of Ionic2Ionic2的离子滚动中的事件“ionScroll”
【发布时间】:2018-07-09 05:27:13
【问题描述】:

好吧,我想在指令 ion-scroll 中触发 ionScroll,但它不起作用。

知道我该如何处理这个吗???

API:https://ionicframework.com/docs/api/components/scroll/Scroll/

【问题讨论】:

  • 我在API 中没有看到 ionScroll。
  • 您说您想“触发 ionScroll”,但 API 并未显示该事件是我想说的。你用 ion-scroll 指令干什么呢?
  • 我用纯 DOM 解决了它,但可能是有另一种方式......

标签: angular ionic-framework ionic2 ion-scroll


【解决方案1】:

如果您或其他人仍在寻找答案,我会发布此信息。

您可以使用ion-infinite-scroll,但它仅适用于ion-content,如果适合您,您可以使用它。

但是,如果你真的想从ion-scroll 获取事件,你可能想尝试这样的事情: https://stackoverflow.com/a/42176764/4084776

如果您想检查何时到达滚动底部,您可以添加一个虚拟元素并检查它是否靠近滚动底部。请参阅下面的示例。

  ...
  @ViewChild(Scroll) ionScroll: Scroll;
  @ViewChild("endOfScroll") endOfScroll: ElementRef;
  updating: Boolean = false;
  private threshold: number = 0.01; //1% This is similar to ion-infinite-scroll threshold 
  ...
  ionViewDidLoad() { 
      this.ionScroll.addScrollEventListener(this.scrollHandler.bind(this));
  }
  ...
  scrollHandler(evenman){
    let endOfScroll = this.endOfScroll.nativeElement.getBoundingClientRect();
    let ionScroll = this.ionScroll._scrollContent.nativeElement.getBoundingClientRect();
    let clearance = 1 - ionScroll.bottom/endOfScroll.bottom;
    if(clearance <= this.threshold){
      this.updating = true;
      // DO your work here
      console.log(JSON.stringify({fen: endOfScroll.bottom, lis: ionScroll.bottom}));
      this.updating = false;

    }
  }
...
...
      <ion-scroll scrollY="true">
        <ion-list>
          <ion-item-sliding *ngFor="let machann of lisMachann.lisMachann  let endeks = index" [class.active]="endeks == endeksKlik">
            <ion-item (click)="ouveFenet(endeks)">
            ...
            </ion-item>
            <ion-item-options side="left">
            ...
            </ion-item-options>
          </ion-item-sliding>
          <ion-item *ngIf="updating">
            <ion-spinner class="loading-center"></ion-spinner>
          </ion-item>
        </ion-list>
        <div #endOfScroll></div>
      </ion-scroll>
...

【讨论】:

    猜你喜欢
    • 2017-08-26
    • 1970-01-01
    • 1970-01-01
    • 2017-10-21
    • 2017-08-24
    • 1970-01-01
    • 2018-10-14
    • 1970-01-01
    • 2017-10-01
    相关资源
    最近更新 更多