ionic 面包屑导航

1、bread-crumb.ts文件

  在 ionic 中 NavController 是导航控制组件的基础类,在面包屑导航中将使用该对象实例的 length()、remove(startIndex, removeCount, opts)、push(page, params, opts)方法:

length(): 返回该导航控制器的视图数量。
remove(startIndex, removeCount, opts):从导航堆栈中的指定索引处移除 removeCount 个页面
(该移除是移除索引后面页面,所以研移除多个页面要将该索引移动到 length()-removeCount 处)
push(page, params, opts):将页面压进当前导航堆栈顶部

源码:

import { Component, Input} from '@angular/core';
import { NavController } from 'ionic-angular';

@Component({
  selector: 'bread-crumb',
  templateUrl: 'bread-crumb.html',
})
export class BreadCrumb {

  @Input() private nextPage; // 下一个页面
  @Input() private curPageId;  // 当前页面ID
  constructor(  public navCtrl: NavController) {}


  /*
  * 面包屑导航控制
  */
  navClick(event){
    let dif = this.curPageId - event.target.id;
     if( dif > 0 ){
        this.navCtrl.remove(this.navCtrl.length() - dif, dif);
     } else if (dif === -1 && this.nextPage){
       this.navCtrl.push(this.nextPage);
     }

  }
}

2、bread-crumb.html文件

<div class="nav-container" >
  <span [ngClass]="{'curPage': curPageId === 1 }" class="center-y nav-control-1" id=1 (click)="navClick($event)">页面1</span>
  <span [ngClass]="{'curPage': curPageId === 2 }" class="center-y nav-control-2" id=2 (click)="navClick($event)">页面2</span>
  <span [ngClass]="{'curPage': curPageId === 3 }" class="center-y nav-control-3" id=3 (click)="navClick($event)">页面3</span>
  <span [ngClass]="{'curPage': curPageId === 4 }" class="center-y nav-control-4" id=4 (click)="navClick($event)">页面4</span>
  <span [ngClass]="{'curPage': curPageId === 5 }" class="center-y nav-control-5" id=5 (click)="navClick($event)">页面5</span>
</div>

3、bread-crumb.scss文件

.nav-container{
  position: relative;
  width: 100%;
  min-height: 40px;
  background: #ccc;

}

.nav-container > span {
  position: absolute;
  width: 20%;
  min-height: 40px;
  line-height: 40px;;

}

.nav-container > span{
  z-index: 10;
  color: #fff;
  text-align: center;
  font-size: 1.5rem;
}

.nav-control-1{
  left: 0;
}
.nav-control-2{
  left: 20%;
}
.nav-control-3{
  left: 40%;

}
.nav-control-4{
  left: 60%;
}
.nav-control-5{
  left: 80%;
}
.curPage{
  color: black !important;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值