如何在离子内容滚动时自动隐藏按钮,并在滚动停止时显示

时间:2018-06-18 06:16:36

标签: html css ionic-framework ionic3 scrollview

这是我使用scroll function事件的HTML文件。

<ion-content (ionScroll)="scrollFunction($event)">
    <ion-card *ngFor="let product of products" no-padding>
    <ion-item class="bigclass">
     <ion-thumbnail item-height="100px" item-start>
       <img-loader *ngIf="product.images" src="{{product.images[0].src}}" useImg></img-loader>
     </ion-thumbnail>
    </ion-card>
    <ion-infinite-scroll (ionInfinite)="loadMoreProducts($event)">
     <ion-infinite-scroll-content></ion-infinite-scroll-content>
    </ion-infinite-scroll> 
</ion-content>
<ion-footer>
    <button class="proceed" *ngIf="isShown" ion-button full (click)="proceedPayment()">Proceed</button>
</ion-footer>    

这是我的.ts文件。它在向下滚动事件时隐藏按钮但未显示。当我向上或向下滚动时,我希望它能够正常工作。按钮。它应该隐藏,当ion-content的滚动停止时,按钮应该可见。

public isShown:bolean=false;
constructor(public navCtrl:NavController){
    this.WooCommerce.getAsync('products?
      consumer_key=ck&consumer_secret=cs').then((result) => {
      console.log(JSON.parse(result.toJSON().body));
      this.products = JSON.parse(result.toJSON().body);
      console.log(this.products);
      this.products.forEach(product => { product.quantity = 1, 
      product.disabled=false;});
      return JSON.parse(result.toJSON().body);         
    }, (err) => {
      console.log(err)  
    })
}

public scrollFunction = (event: any) => {
    let dimensions = this.content.getContentDimensions(); 
    let bottomPosition = dimensions.contentHeight + dimensions.scrollTop; 
    let screenSize = dimensions.scrollHeight;
    this.isShown = screenSize - bottomPosition <= 10 ? true : false;
}

1 个答案:

答案 0 :(得分:0)

您可以在ion-content

上绑定以下方法
  • ionScrollStart
  • <强> ionScrollEnd

    <ion-content (ionScrollStart)="scrollStart($event)" (ionScrollEnd)="scrollStart($event)

并通过更新isShown

来处理此事件
  scrollStart(event) {
     this.isShown = false;
   }

  scrollStop(event) {
     this.isShown = true;
  }