vue横向滚动导航栏

直接上代码

<div class="navBox">
        <ul class="ul">
          <li 
          class="li" 
          :class="{'li-activate': navIndex == index}" 
          v-for="(item, index) in items" 
          :key="index" 
          @click="handleNavClick(index)"
          >
           	 {{item.label}}
          	 <div :class="{'navBox-li-line': navIndex == index}"></div>
          </li>
        </ul>
      </div>
 data() {
    return {
    	items: [
        {
          label: '1111'
        },
        {
          label: '2222'
        },
        {
          label: '3333'
        },
        {
          label: '4444'
        },
        {
          label: '5555'
        },
        {
          label: '6666'
        }
      ],
      subRouteUrl: [
        '/Solution/showroom', 
        '/Solution/partybuild', 
        '/Solution/technology', 
        '/Solution/realitymuseum', 
        '/Solution/cultural', 
        '/Solution/safetymuseum'
      ],
      navIndex: 0
    };
  },
  methods: {
    handleNavClick (index) {
      this.navIndex = index;
      this.$router.push(this.subRouteUrl[index])
    }
  },
  created () {
    
    let path = this.$route.path;
    for(let i = 0; i < this.subRouteUrl.length; i++){
      if(path == this.subRouteUrl[i]){
        this.navIndex = i;
      }
    }
  
  },
.navBox {
  width: 100%;
  height: 3.5rem;
  background: #ffffff;
}
.navBox .ul {
  width: 100%;
  padding: 0;
  margin: 0;
  list-style: none;
  overflow: auto;
  //在ios上滚动圆滑
  -webkit-overflow-scrolling : touch;
  white-space: nowrap;
  position: relative;
  padding: 0rem 0.8rem;
  box-sizing: border-box;
}
.navBox .ul .li {
  width: auto;
  height: 100%;
  line-height: 3.5rem;
  margin-right: 0.5rem;
  display: inline-block;
  position: relative;
}
.navBox .ul .li .navBox-li-line {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: #08568d;
}
.navBox .ul .li-activate {
  color: #08568d;
}
.navBox .ul::-webkit-scrollbar {
  display: none;
}

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值