工具栏的水平滚动在Mobile上不起作用

时间:2019-02-04 07:12:57

标签: android angular css3 ionic-framework ionic3

enter image description here

我正在构建一个离子应用程序,在其中添加了工具栏标题,它具有5个可导航的按钮。 但是,当我在浏览器设备上尝试代码时,水平滚动条对于工具栏工作正常,但在实际设备中,它将无法正常工作。有时会滚动,有时不会。 下面是相同的代码。

<ion-header>
  <ion-navbar color="light">
    <ion-title>Home</ion-title>
    <ion-buttons end>
      <button ion-button icon-only>
        <ion-icon name="search"></ion-icon>
      </button>
      <button ion-button icon-only>
        <ion-icon name="cart"></ion-icon> 
      </button>
    </ion-buttons>
  </ion-navbar>
  <ion-toolbar color="light">
    <ion-buttons>
      <button ion-button clear>{{'All'|translate}}</button>
    </ion-buttons>
    <ion-buttons *ngFor="let facet of parentCategories">
      <button ion-button [ngClass]=" {'active' : selectedFacet == facet}">{{facet}}
      </button>
      <button ion-button icon-only clear class="accordion" (tap)="getSubFacets(facet);accordion(event)" *ngIf="selectedFacet == facet"><ion-icon name="ios-arrow-down"></ion-icon></button>
    </ion-buttons>
    <div id="sub-category" class="sub-category">
      <ion-buttons *ngFor="let subFacet of childCategories">
        <button ion-button [ngClass]=" {'active' : selectedSubFacet == subFacet}" (tap)="getFilteredProducts('categoryFacet',subFacetMap.get(subFacet), selectedFacet, subFacet)">
          {{subFacet}}</button>
      </ion-buttons>
    </div>
  </ion-toolbar>
</ion-header>

css:

.toolbar-content {
     overflow-x: auto;
     white-space: nowrap;
     overflow-y: hidden;
     width: 100%;
     height: 56px;
}

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,我遵循了这个示例

CSS:

ion-toolbar.scrollable-segments {
ion-segment {
  display: block;
  overflow-x: scroll;
  white-space: nowrap;

  ion-segment-button.segment-button {
    display: inline-block;
    width: auto;
  }
 }
}

HTML:

<ion-toolbar no-border class="scrollable-segments">
<ion-segment [(ngModel)]="segment">
    <ion-segment-button value="all">
        All
    </ion-segment-button>
    <ion-segment-button value="test">
        Recent
    </ion-segment-button>
    <ion-segment-button value="test2">
        Recent
    </ion-segment-button>
    <ion-segment-button value="test3">
        Recent
    </ion-segment-button>
    <ion-segment-button value="test4">
        Recent
    </ion-segment-button>
    <ion-segment-button value="test5">
        Recent
    </ion-segment-button>
    <ion-segment-button value="test6">
        Recent
    </ion-segment-button>
    <ion-segment-button value="test7">
        Recent
    </ion-segment-button>
</ion-segment>
</ion-toolbar>

参考: https://forum.ionicframework.com/t/horizontally-scrolling-sub-header-in-ionic-2/42722/8

答案 1 :(得分:1)

尝试一下,它的工作代码,经过测试并经过测试

HTML:

  <ion-toolbar color="light">
    <div style="overflow-x: scroll;width: 100%">
      <ion-row nowrap>
        <ion-buttons>
          <button ion-button clear>All</button>
        </ion-buttons>
        <ion-buttons *ngFor="let facet of countries">
          <button ion-button>
            {{facet.item}}
          </button>
          <button ion-button icon-only clear class="accordion" (tap)="getSubFacets(facet);accordion(event)" *ngIf="selectedFacet == facet">
            <ion-icon name="ios-arrow-down"></ion-icon>
          </button>
        </ion-buttons>
      </ion-row>
    </div>
  </ion-toolbar>