【问题标题】:Auto-hide Floating Action Button in Ionic 4Ionic 4 中的自动隐藏浮动操作按钮
【发布时间】:2019-10-02 20:10:01
【问题描述】:

我想在用户 scrollToBottom 时显示 scrollToTop 按钮,而当用户在顶部时只显示 scrollToBottom。如何管理按钮请帮助我...这是我的屏幕截图请帮助我如何管理这些按钮。

tab1.page.ts

    <ion-content cache-view="false" (ionScrollStart)="logScrollStart()" (ionScroll)="logScrolling($event)"
  (ionScrollEnd)="logScrollEnd()" [scrollEvents]="true">

  <ion-fab vertical="bottom" horizontal="end" slot="fixed">
      <ion-fab-button *ngIf="showToolbar" (click)="ScrollToTop($event)">
        <ion-icon name="arrow-dropup"></ion-icon>
      </ion-fab-button>
    </ion-fab>

    <ion-fab vertical="top" horizontal="end" slot="fixed">
      <ion-fab-button  (click)="ScrollToBottom($event)">
        <ion-icon name="arrow-dropdown"></ion-icon>
      </ion-fab-button>
    </ion-fab>

</ion-content>

tab1.page.ts

 ScrollToTop(event){
    this.content.ionScrollEnd.subscribe((data)=>{
      if(this.content){
        //console.log(data);
       this.showToolbar = true;
      }
     });
    this.content.scrollToTop(1500);

  }
  ScrollToBottom(){
    this.content.scrollToBottom(1500);
  }
  logScrollStart(){

   // console.log("logScrollStart : When Scroll Starts");
  }

  logScrolling(){


  }

  logScrollEnd(){
    this.content.ionScrollEnd.subscribe((data)=>{
      if(this.content){
        //console.log(data);
       this.showToolbar = true;
      }
     });

【问题讨论】:

    标签: ionic-framework ionic4


    【解决方案1】:

    也许这有帮助

    <ion-content cache-view="false" (ionScrollStart)="logScrollStart()" (ionScroll)="logScrolling($event)"
          (ionScrollEnd)="logScrollEnd()" [scrollEvents]="true">
    
      <ion-fab *ngIf="showTop" vertical="bottom" horizontal="end" slot="fixed">
        <ion-fab-button *ngIf="showToolbar" (click)="ScrollToTop($event)">
          <ion-icon name="arrow-dropup"></ion-icon>
        </ion-fab-button>
      </ion-fab>
    
      <ion-fab  *ngIf="showBottom" vertical="top" horizontal="end" slot="fixed">
        <ion-fab-button  (click)="ScrollToBottom($event)">
          <ion-icon name="arrow-dropdown"></ion-icon>
        </ion-fab-button>
      </ion-fab>
    
    </ion-content>
    

    ScrollToTop(event){
      this.content.ionScrollEnd.subscribe((data)=>{
        if(this.content){
          //console.log(data);
          this.showToolbar = true;
        }
      });
      this.content.scrollToTop(1500);
      this.showBottom=true;
      this.showTop=false;
    }
    
    ScrollToBottom(){
      this.content.scrollToBottom(1500);
      this.showTop=true;
      this.showBottom=false;
    }
    

    【讨论】:

    • this.showTop=true; this.showBottom=false;如何设置这个变量
    • 在 tab1.page.ts 就在构造函数之前添加:showTop=false;showBottom=true;
    猜你喜欢
    • 2016-07-27
    • 1970-01-01
    • 1970-01-01
    • 2020-05-28
    • 1970-01-01
    • 2015-12-13
    • 2015-12-03
    • 2021-01-27
    • 2016-06-24
    相关资源
    最近更新 更多