小程序导航栏

效果在这里插入图片描述

页面

<!--pages/NCPQualitySafety/planting/information.wxml-->
<wxs src="../../../utils/filter.wxs" module="filters" />
<view class="container">
  <scroll-view scroll-x="true" class="nav" scroll-left="{{navScrollLeft}}" scroll-with-animation="{{false}}">
    <block wx:for="{{navData}}" wx:for-index="idx" wx:for-item="navItem" wx:key="idx">
      <view class="nav-item {{currentTab == idx ?'active':''}}" data-current="{{idx}}" bindtap="switchNav">
        {{navItem.text}}</view>
    </block>
  </scroll-view>
  <!-- 页面内容 -->
  <!-- 页面内容 -->
  <swiper class="tab-box" current="{{currentTab}}" duration="300" bindchange="switchTab">
   
    <swiper-item class="tab-content">
    第一个内容
     </swiper-item>
    <swiper-item class="tab-content">
    第二个内容
         </swiper-item>
             <swiper-item class="tab-content">
    第三个内容
         </swiper-item>
           </swiper>
</view>

JS

data:{
 navScrollLeft: 0,
     currentTab: 0,
  navData: [
 
      {
        text: '人兽共患病'
      },
      {
        text: '一般宠物传染病'
      },
      {
        text: '其他宠物疾病'
      },
     
     
    ],
}
  switchNav(event) {
    var cur = event.currentTarget.dataset.current;
    //console.log(event)
    //每个tab选项宽度占1/5
    var singleNavWidth = this.data.windowWidth / 2;
    //tab选项居中                            
    this.setData({
      navScrollLeft: (cur - 2) * singleNavWidth
    })
    if (this.data.currentTab == cur) {
      return false;
    } else {
      this.setData({
        currentTab: cur
      })
    }
  },

样式

.nav {
  height: 80rpx;
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  line-height: 80rpx;
  background: #f7f7f7;
  font-size: 16px;
  white-space: nowrap;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 99;
}
.nav-item {
  /* width: 30%; */
  padding-left:20px;
  padding-right: 20px;
  display: inline-block;
  text-align: center;
}
.nav-item.active {
  line-height: 70rpx;
  text-align: center;
  color: #1485ee;
  flex: 1;
  border-top: 0px;
  border-bottom: 3px solid #1485ee;
  font-weight: bold;
  font-size: 28rpx;
}
.scroll-view {
  /*width:228px;*/
  font-size:13px;
  width: 50%;
  height: 220px;
  position: fixed;
  margin-top: 48px;
  /* text-align: center; */
  margin-left: 120px;
  /* margin-left: 65px;  */
  /* background-color: #cbcbcbf8; */
  /* background-color: #6464648c; */
  background-color: #e7e7e7;
  -moz-box-shadow: 0px 0px 2px #e2e2e2;
  -webkit-box-shadow: 0px 0px 2px #e2e2e2;
  box-shadow: 0px 0px 2px #e2e2e2;
    border-bottom-right-radius:8px;
    border-bottom-left-radius:8px;
    
  z-index:3;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值