Home > WeChat Applet > Mini Program Development > WeChat Mini Program: Example of how to implement tabs effect

WeChat Mini Program: Example of how to implement tabs effect

高洛峰
Release: 2018-05-29 15:01:21
Original
5118 people have browsed it

The little girl also just started using the WeChat applet. She found that many components inside WeChat have been packaged, but there is no component with tab effect. She just needs to use it recently, so she did some research. It has been sorted out for everyone to discuss and learn together. If there are any problems or areas that can be improved, everyone is welcome to comment and complain.

First of all, two variables are required when clicking on the navigation. One is to store the current click style class, and the other is the default style class for other navigations.

The tab content list also requires two variables. , one stores the current display block, and the other stores other hidden default blocks

Use trinocular operation to obtain the navigation index by clicking, and judge whether to add the current class based on the index [Note, here I bind the click event to Parent navigation bar, get the event object properties triggered by click through the target object]

Please combine the following renderings:

 微信小程序:如何实现tabs选项卡效果示例

demo.wxml:

<blockquote><view class="tab">
Copy after login

demo.js

Page( {  
  data: {  
    tabArr: {  
      curHdIndex: 0,  
      curBdIndex: 0  
    },  
  },  
  tabFun: function(e){  
    //获取触发事件组件的dataset属性  
    var _datasetId=e.target.dataset.id;  
    console.log("----"+_datasetId+"----");  
    var _obj={};  
    _obj.curHdIndex=_datasetId;  
    _obj.curBdIndex=_datasetId;  
    this.setData({  
      tabArr: _obj  
    });  
  },  
  onLoad: function( options ) {  
    alert( "------" );  
  }  
});
Copy after login

demo.wxss

.tab{  
    display: flex;  
    flex-direction: row;  
}  
.tab-left{  
    width: 200rpx;  
    line-height: 160%;  
    border-right: solid 1px gray;  
}  
.tab-left view{  
    border-bottom: solid 1px red;  
}  
.tab-left .active{  
    color: #f00;  
}  
.tab-right{  
    line-height: 160%;  
}  
.tab-right .right-item{  
    padding-left: 15rpx;  
    display: none;  
}  
.tab-right .right-item.active{  
    display: block;  
}
Copy after login

The final demonstration effect is as follows:

 微信小程序:如何实现tabs选项卡效果示例

 微信小程序:如何实现tabs选项卡效果示例

Summary: The principle of Kagami_Tiger is to select a tab, call the selected tab content and hide the content of other tabs. Of course, if you can classify each tab on a different page, then each tab corresponds to each different one one by one. page, that might be better. I haven't developed it that way, and I welcome everyone to share it. Only by learning from each other can we make progress together.

More WeChat applet: How to implement tabs tab effect example For related articles, please pay attention to the PHP Chinese website!

Related articles:

Realization of WeChat mini program tabs effect

Simple and stylish pure CSS3 Tabs tab effect

javascript implements tab switching effect

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template