Chinaunix首页 | 论坛 | 博客
  • 博客访问: 930046
  • 博文数量: 210
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2070
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-19 21:54
文章分类

全部博文(210)

文章存档

2020年(2)

2019年(18)

2018年(27)

2017年(5)

2016年(53)

2015年(88)

2014年(17)

分类: 其他平台

2017-12-17 20:55:51

微信小程序 tabs选项卡效果的实现的相关资料,微信小程序内部组件没有Tabs 选项卡的功能。

1.首先点击导航的时候需要两个变量,一个存储当前点击样式类,一个是其它导航默认的样式类

2.选项卡内容列表同样也需要两个变量,一个存储当前显示块,一个存储的是其它隐藏的默认块

3.使用三目运算通过点击获取导航索引,根据索引判断是否添加当前类【备注,这里我将点击事件绑定在父级导航栏,通过target对象得到点击触发的事件对象属性】


WXML代码:

点击(此处)折叠或打开

  1. <view class="tab">
  2. <view class="tab-left" bindtap="tabFun">
  3.  <view class="{{tabArr.curHdIndex=='0'? 'active' : ''}}" id="tab-hd01" data-id="0">tab-hd01</view>
  4.  <view class="{{tabArr.curHdIndex=='1'? 'active' : ''}}" id="tab-hd02" data-id="1">tab-hd01</view>
  5.  <view class="{{tabArr.curHdIndex=='2'? 'active' : ''}}" id="tab-hd03" data-id="2">tab-hd01</view>
  6.  <view class="{{tabArr.curHdIndex=='3'? 'active' : ''}}" id="tab-hd04" data-id="3">tab-hd01</view>
  7. </view>
  8.  
  9. <view class="tab-right">
  10.  <view class="right-item {{tabArr.curBdIndex=='0'? 'active' : ''}}">tab-bd01</view>
  11.  <view class="right-item {{tabArr.curBdIndex=='1'? 'active' : ''}}">tab-bd02</view>
  12.  <view class="right-item {{tabArr.curBdIndex=='2'? 'active' : ''}}">tab-bd03</view>
  13.  <view class="right-item {{tabArr.curBdIndex=='3'? 'active' : ''}}">tab-bd04</view>
  14. </view>
  15. </view>
js代码:

点击(此处)折叠或打开

  1. Page( {
  2. data: {
  3.  tabArr: {
  4.   curHdIndex: 0,
  5.   curBdIndex: 0
  6.  },
  7. },
  8. tabFun: function(e){
  9.  //获取触发事件组件的dataset属性
  10.  var _datasetId=e.target.dataset.id;
  11.  console.log("----"+_datasetId+"----");
  12.  var _obj={};
  13.  _obj.curHdIndex=_datasetId;
  14.  _obj.curBdIndex=_datasetId;
  15.  this.setData({
  16.   tabArr: _obj
  17.  });
  18. },
  19. onLoad: function( options ) {
  20.  alert( "------" );
  21. }
  22. })
WXSS代码:

点击(此处)折叠或打开

  1. .tab{
  2.  display: flex;
  3.  flex-direction: row;
  4. }
  5. .tab-left{
  6.  width: 200rpx;
  7.  line-height: 160%;
  8.  border-right: solid 1px gray;
  9. }
  10. .tab-left view{
  11.  border-bottom: solid 1px red;
  12. }
  13. .tab-left .active{
  14.  color: #f00;
  15. }
  16. .tab-right{
  17.  line-height: 160%;
  18. }
  19. .tab-right .right-item{
  20.  padding-left: 15rpx;
  21.  display: none;
  22. }
  23. .tab-right .right-item.active{
  24.  display: block;
  25. }




阅读(2450) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~