zoukankan      html  css  js  c++  java
  • 微信小程序自定义选项卡

    本篇博客介绍在微信小程序中如何自定义选项卡

    效果如下:

    shopping.wxml:

    <view class='topTabSwiper'>
      <view class='tab  {{currentData == 0 ? "tabBorer" : ""}}' data-current="0" bindtap='checkCurrent'>美食</view>
      <view class='tab  {{currentData == 1 ? "tabBorer" : ""}}' data-current="1" bindtap='checkCurrent'>旅游</view>
      <view class='tab  {{currentData == 2 ? "tabBorer" : ""}}' data-current="2" bindtap='checkCurrent'>生活</view>
      <view class='tab  {{currentData == 3 ? "tabBorer" : ""}}' data-current="3" bindtap='checkCurrent'>特产</view>
      <view class='tab  {{currentData == 4 ? "tabBorer" : ""}}' data-current="4" bindtap='checkCurrent'>热卖</view>
    </view>
    <swiper current="{{currentData}}" class='swiper' style="height:600px;" duration="300" bindchange="bindchange">
      <swiper-item>
        <view class='swiper_con'>welcome come to 美食</view>
      </swiper-item>
      <swiper-item>
        <view class='swiper_con'>welcome come to 旅游</view>
      </swiper-item>
      <swiper-item>
        <view class='swiper_con'>welcome come to 生活</view>
      </swiper-item>
      <swiper-item>
        <view class='swiper_con'>welcome come to 特产</view>
      </swiper-item>
      <swiper-item>
        <view class='swiper_con'>welcome come to 热卖</view>
      </swiper-item>
    </swiper>

    shopping.js:

    Page({
      /**
       * 页面的初始数据
       */
      data: {
        currentData: 0,
      },
      //获取当前滑块的index
      bindchange: function (e) {
        const that = this;
        that.setData({
          currentData: e.detail.current
        })
      },
      //点击切换,滑块index赋值
      checkCurrent: function (e) {
        const that = this;
        if (that.data.currentData === e.target.dataset.current) {
          return false;
        } else {
          that.setData({
            currentData: e.target.dataset.current
          })
        }
      }
    })

    shopping.wxss:

    .tab {
      float: left;
       20%;
      text-align: center;
      padding: 10rpx 0;
    }
    
    /* 导航栏整体样式 */
    .topTabSwiper {
      background-color: white;
      padding: 2% 0;
    }
    
    .topTabSwiper:after {
      content: "";
      clear: both;
      display: block;
    }
    
    /* 选中样式 */
    .tabBorer {
      color: red;
      border-bottom: 2px solid red;
    }
    
    .swiper swiper-item {
      text-align: center;
      margin-top: 50rpx;
    }

    END!

  • 相关阅读:
    【Zookeeper】分布式服务框架 Zookeeper -- 管理分布式环境中的数据
    【Consul】 分布式环境中的服务注册和发现利器
    springboot集成springsession利用redis来实现session共享
    OpenResty初涉
    java面试之闭包(closure)
    集合框架学习之Guava Collection
    本地缓存
    VLFeat在matlab和vs中安装
    HashCode与Equals回顾
    集合工具类CollectionUtils、ListUtils、SetUtils、MapUtils的使用
  • 原文地址:https://www.cnblogs.com/gygg/p/12660316.html
Copyright © 2011-2022 走看看