zoukankan      html  css  js  c++  java
  • 微信小程序切换标签改变样式

    微信小程序切换标签改变样式

    swichtab

    wxml

    <!--顶部导航栏-->
    <view class="swiper-tab">
        <view class="tab-item {{currentTab==0 ? 'active' : ''}}" data-current="0" bindtap="swichNav">A</view>
        <view class="tab-item {{currentTab==1 ? 'active' : ''}}" data-current="1" bindtap="swichNav">B</view>
        <view class="tab-item {{currentTab==2 ? 'active' : ''}}" data-current="2" bindtap="swichNav">C</view>
    </view>
    
    <!--内容主体-->
    <swiper class="swiper" current="{{currentTab}}" duration="400" bindchange="swiperChange">
        <block wx:for="{{tabs}}" wx:key="item">
            <swiper-item>
                <view>{{item}}</view>
            </swiper-item>
        </block>
    </swiper>
    

    wxss

    .swiper-tab {
      display: flex;
      flex-direction: row;
      line-height: 60rpx;
      border-bottom: 2rpx solid #777;
    }
    
    .tab-item {
       33.3%;
      text-align: center;
      font-size: 15px;
      color: rgb(235, 135, 135);
    }
    
    .swiper {
       100%;
      font-size: 100rpx;
      height: 1140rpx;
      background: #dfdfdf;
    }
    
    .active {
      color: blue;
      border-bottom: 5rpx solid blue;
    }
    

    js

    Page({
      data: {
        // tab切换
        currentTab: 0,
        tabs: ["A", "B", "C"],
      },
      swichNav: function (e) {
        // console.log(e);
        var that = this;
        if (this.data.currentTab === e.target.dataset.current) {
          return false;
        } else {
          that.setData({
            currentTab: e.target.dataset.current,
          });
        }
      },
      swiperChange: function (e) {
        // console.log(e);
        this.setData({
          currentTab: e.detail.current,
        });
      },
    });
    

    The_End

  • 相关阅读:
    正则表达式学习
    《代码整洁之道》阅读笔记
    PHP手册阅读笔记(一)——XXX
    2014年终总结和2015年规划
    linux之帮助命令——help,man,whereis简介
    企业中git管理代码的基本流程
    推荐几款画韦恩图的在线工具
    HTTPContent-Type的含义
    s s
    asp.net core ServiceProvider
  • 原文地址:https://www.cnblogs.com/codehhr/p/13863604.html
Copyright © 2011-2022 走看看