ionic2+ 使用slides制作滑動(dòng)效果的類型選擇欄

效果圖:

20160912135110197.gif
1.在所需頁(yè)面的html中,加入
 <ion-slides class="slide-title" [slidesPerView]="pageNumber" [pager]="false">
    <ion-slide *ngFor="let slide of slides; let i = index;">
      <div (click)="onClick(i,slide)">
        <span class="slide-title-unit" [ngClass]="{'slide-title-active': selectedIndex == i}">{{slide}}</span>
      </div>
    </ion-slide>
  </ion-slides>
2.scss文件中,加入樣式(可根據(jù)自己需要更改)
$slide-height-small: 4.2rem;
$slide-height-large: 4.2rem;

.slide-title {
  width: 100%;
  height: $slide-height-small;
  color: #666666;
  background-color: map_get($colors, primary);
  padding: 0;
  border-bottom:2px solid map_get($colors, light);
}

.slide-title-unit {
  padding-bottom: 0.6rem;
  font-size: 1.6rem;
  color: white;
  height: $slide-height-small;
  line-height: $slide-height-small;
}

.slide-title-active {
  border-bottom: 3px solid yellow;
  color: yellow;
}

3.ts中設(shè)置選項(xiàng)卡
    slides: string[] = ['推薦', '熱點(diǎn)', '視頻','手機(jī)','科技','問答','汽車','社會(huì)','數(shù)碼'];//顯示的數(shù)據(jù)
    pageNumber: number = 6;//同時(shí)顯示的個(gè)數(shù)
    selectedIndex: number = 0;//默認(rèn)選中的

至此完成。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。