zoukankan      html  css  js  c++  java
  • 小程序之选项卡切换(纵向)

    选项卡算是小程序中必不可少,大家基本上都会用到的一个功能组件,今天就来分享一个自己做的效果,纵向的一个选项卡

    wxml 

    <view class='productNav'>
      <!-- 左侧 -->
      <view class='left'>
        <view class="{{active==0?'selected':'normal'}}" id="0" bindtap='switchNav'>牙齿清洁</view>
        <view class="{{active==1?'selected':'normal'}}" id="1" bindtap='switchNav'>牙齿矫正</view>
        <view class="{{active==2?'selected':'normal'}}" id="2" bindtap='switchNav'>牙齿种植</view>
        <view class="{{active==3?'selected':'normal'}}" id="3" bindtap='switchNav'>牙齿治疗</view>
        <view class="{{active==4?'selected':'normal'}}" id="4" bindtap='switchNav'>拔牙补牙</view>
        <view class="{{active==5?'selected':'normal'}}" id="5" bindtap='switchNav'>牙齿美容</view>
      </view>
      <!-- 右侧 -->
      <view class='right'>
        <view class='type'>
          <!-- current:当前所在滑块的 index -->
          <!-- vertical:滑动方向是否为纵向 -->
          <swiper class="swiper-item" current='{{currentTab}}' vertical='{{true}}'>
            <!-- catchtouchmove 阻止弹窗后滚动穿透 -->
            <swiper-item id="0" catchtouchmove="false">
              牙齿清洁
            </swiper-item>
            <swiper-item id="1" catchtouchmove="false">
              牙齿矫正
            </swiper-item>
            <swiper-item id="2" catchtouchmove="false">
              牙齿种植
            </swiper-item>
            <swiper-item id="3" catchtouchmove="false">
              牙齿治疗
            </swiper-item>
            <swiper-item id="4" catchtouchmove="false">
              拔牙补牙
            </swiper-item>
            <swiper-item id="5" catchtouchmove="false">
              牙齿美容
            </swiper-item>
          </swiper> 
        </view>
      </view>
    </view>

    wmss

    /* 选项卡 */
    .productNav{
      display: flex;
      flex-direction: row;
      font-family: "Microsoft YaHei"
    }
    .left{
       25.3%;
      font-size: 30rpx;
      background-color: #f4f4f4;
    }
    .left view{
      text-align: center;
      height: 95rpx;
      line-height: 95rpx;
    }
    .selected{
      background-color: #fff; 
      font-weight: bold;
      color: #E54847;
    }
    .normal{
      background-color: #f4f4f4;
      border-bottom: 1px solid #f2f2f2;
    }
    .right{
      74%;
      margin: 0;
    }
    swiper{
      height: 1050rpx;
    }
    .swiper-item view{
       540rpx;
      height: 200rpx;
      padding: 25rpx 0 25rpx 20rpx;
      border-bottom: 1rpx solid #ccc;
    }
    

     js

    Page({
      data: {
        active: 0,
        currentTab: 0
      },
      // 选项卡  主要是通过判断e.target.id的值 设置对应的id显示
      switchNav: function (e) {
        var page = this;
        var id = e.target.id;
        if (this.data.currentTab == id) {
          return false;
        } else {
          page.setData({
            currentTab: id
          });
        }
        page.setData({
          active: id
        });
      }
    })
  • 相关阅读:
    python 操作数据库
    python学习
    Java学习(十)
    Java学习(九)
    Java学习(八)
    Java学习(七)
    Java学习(六)
    Java学习(五)
    Java学习(四)
    Java学习(三)
  • 原文地址:https://www.cnblogs.com/jzbs/p/12628494.html
Copyright © 2011-2022 走看看