Ionic 4 : Hide ion-tab-bar while scrolling, just like LinkedIn app

柔情痞子 提交于 2019-12-07 13:35:37

问题


I am using default ion-tab-bar with bottom placement as shown in the LinkedIn app. I want to hide the tab-bar while scrolling and show it again when scrolling stops. This feature can be seen in the LinkedIn app.

Here is tabs.page.html

<ion-tabs >

  <ion-tab-bar slot="bottom" >
    <ion-tab-button tab="tab1">
      <ion-icon name="desktop"></ion-icon>
      <ion-label>Tab Three</ion-label>
    </ion-tab-button>

    <ion-tab-button tab="tab2">
      <ion-icon name="person"></ion-icon>
      <ion-label>Tab Two</ion-label>
    </ion-tab-button>

    <ion-tab-button tab="tab3">
      <ion-icon name="send"></ion-icon>
      <ion-label>Tab Three</ion-label>
    </ion-tab-button>
  </ion-tab-bar>

</ion-tabs>

回答1:


Add this to the tab.page.ts

  ngOnInit() {
    let content = document.querySelector('ion-content');
    content.scrollEvents = true;
    content.addEventListener('ionScrollStart', () => {
          document.querySelector('ion-tab-bar').style.display = 'none';
    });
    content.addEventListener('ionScrollEnd', () => {
          document.querySelector('ion-tab-bar').style.display = 'flex';
    });
   }

This will do the trick...



来源:https://stackoverflow.com/questions/54307676/ionic-4-hide-ion-tab-bar-while-scrolling-just-like-linkedin-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!