码迷,mamicode.com
首页 > 微信 > 详细

微信小程序实现滑动tab切换和点击tab切换并显示相应的数据(附源代码)

时间:2018-09-02 20:22:25      阅读:727      评论:0      收藏:0      [点我收藏+]

标签:play   isp   lock   back   ati   width   return   ott   程序实现   

这里主要用到了swiper组件和三目运算,直接上代码, 样式只有三个class,简单粗暴,懒的小伙伴们可以直接拿来用,喜欢的点个支持

<view>
  <view class="swiper-tab">
    <view class="bre swiper-tab-list {{tab==0 ? ‘on‘ : ‘‘}}" data-current="0" bindtap="tab_click">图文详情</view>
    <view class="swiper-tab-list {{tab==1 ? ‘on‘ : ‘‘}}" data-current="1" bindtap="tab_click">产品参数</view>
  </view>
  <swiper current="{{tab}}" class="swiper-box" duration="300" style="height:{{winHeight - 31}}px" bindchange="tab_slide">
    <swiper-item>
      图文详情
    </swiper-item>
 
    <swiper-item>
      产品参数
    </swiper-item>
  </swiper>
</view>
Page({
  data: {
    tab: 0
  },
  tab_slide: function (e) {//滑动切换tab 
    var that = this;
    that.setData({ tab: e.detail.current });
  },
  tab_click: function (e) {//点击tab切换
    var that = this;
    if (that.data.tab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        tab: e.target.dataset.current
      })
    }
  },
})
.swiper-tab{  
    width: 100%;  
    border-bottom: 2rpx solid #eee;  
    text-align: center;  
    line-height: 80rpx;
    background: #fff;
    font-size: 14px;
}  
.on{ 
  color: #dd2727;  
  border-bottom: 5rpx solid #dd2727;
}  
.swiper-tab-list{  
  font-size: 29rpx;  
    display: inline-block;  
    width: 49.5%;  
    color: #333; 
}

原文链接:https://blog.csdn.net/qq_31383345/article/details/53453182

 

微信小程序实现滑动tab切换和点击tab切换并显示相应的数据(附源代码)

标签:play   isp   lock   back   ati   width   return   ott   程序实现   

原文地址:https://www.cnblogs.com/Webzhoushifa/p/9574724.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!