微信小程序> 微信小程序tab切换

微信小程序tab切换

浏览量:1849 时间: 来源:yl107

微信小程序开发中选项卡.在android中选项卡一般用fragment,到了小程序这里瞬间懵逼了.

总算做出来了.分享出来看看.

先看效果:

小程序

再上代码:

1.index.wxml

[html] view plain copy
  1. !--index.wxml--  
  2. view class="swiper-tab"  
  3.     view class="swiper-tab-list {{currentTab==0 ? 'on' : ''}}" data-current="0" bindtap="swichNav"哈哈/view  
  4.     view class="swiper-tab-list {{currentTab==1 ? 'on' : ''}}" data-current="1" bindtap="swichNav"呵呵/view  
  5.     view class="swiper-tab-list {{currentTab==2 ? 'on' : ''}}" data-current="2" bindtap="swichNav"嘿嘿/view  
  6. /view  
  7.   
  8. swiper current="{{currentTab}}" class="swiper-box" duration="300" style="height:{{winHeight - 31}}px" bindchange="bindChange"  
  9.     !-- 我是哈哈 --  
  10.     swiper-item  
  11.       view我是哈哈/view  
  12.     /swiper-item  
  13.     !-- 我是呵呵 --  
  14.     swiper-item  
  15.       view我是呵呵/view  
  16.     /swiper-item  
  17.     !-- 我是嘿嘿 --  
  18.     swiper-item  
  19.       view我是嘿嘿/view  
  20.     /swiper-item  
  21. /swiper  
2.index.wxss

[css] view plain copy
  1. /**index.wxss**/  
  2. .swiper-tab{  
  3.     width100%;  
  4.     border-bottom2rpx solid #777777;  
  5.     text-aligncenter;  
  6.     line-height80rpx;}  
  7. .swiper-tab-list{  font-size30rpx;  
  8.     display: inline-block;  
  9.     width33.33%;  
  10.     color#777777;  
  11. }  
  12. .on{ color#da7c0c;  
  13.     border-bottom5rpx solid #da7c0c;}  
  14.   
  15. .swiper-box{ displayblockheight100%width100%overflowhidden; }  
  16. .swiper-box view{  
  17.     text-aligncenter;  
  18. }  

3.index.js

[javascript] view plain copy
  1. //index.js  
  2. //获取应用实例  
  3. var app = getApp()  
  4. Page( {  
  5.   data: {  
  6.     /** 
  7.         * 页面配置 
  8.         */  
  9.     winWidth: 0,  
  10.     winHeight: 0,  
  11.     // tab切换  
  12.     currentTab: 0,  
  13.   },  
  14.   onLoad: function() {  
  15.     var that = this;  
  16.   
  17.     /** 
  18.      * 获取系统信息 

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎