007-01、微信小程序---组件之swiper(tab切换)
2018-03-29 16:16
906 查看
此tab切换以登录页面为参照。
1、WXMl
2、WXSS
3、JS
1、WXMl
<view class="tab-title"> <block wx:for="{{msg}}" wx:key="mykey"> <view class="tab-name {{currentTab==item.mykey ? 'on' : ''}}" data-current="{{item.mykey}}" bindtap="switchNav">{{item.name}}</view> </block> </view> <view> <form bindsubmit="formSubmit" bindreset="formReset" class="formBox"> <swiper class="swiper-box" current="{{currentTab}}" duration="300" bindchange="bindchange" style="height:{{winHeight - 148}}px"> <swiper-item> <view class="lines"> <view class="lines_text">真实姓名</view> <view class="lines_inp"> <input type="text" /> </view> </view> <view class="lines"> <view class="lines_text">手机号码</view> <view class="lines_inp"> <input type="text" /> </view> </view> <view class="lines"> <view class="lines_text">昵称</view> <view class="lines_inp"> <input type="text" /> </view> </view> <view class="lines"> <view class="lines_text">密码</view> <view class="lines_inp"> <input type="text" password="true" /> </view> </view> <view class="lines"> <view class="lines_text">确认密码</view> <view class="lines_inp"> <input type="text" password="true" /> </view> </view> <button class="btns" bindconfirm="register">注册</button> </swiper-item> <swiper-item> <view class="lines"> <view class="lines_text">用户名</view> <view class="lines_inp"> <input type="text" placeholder="" /> </view> </view> <view class="lines"> <view class="lines_text">密码</view> <view class="lines_inp"> <input type="text" password="true" /> </view> </view> <button class="btns" bindconfirm="logIn">登录</button> </swiper-item> </swiper> </form> </view>
2、WXSS
.tab-title{ display: flex; display: -webkit-flex; width: 86%; margin: 150rpx 7% 0; /*border-bottom: 1px solid #ccc;*/ } .tab-name{ width: 50%; height: 100rpx; line-height: 100rpx; text-align: center; } .on{ color: blue; border-bottom: 2px solid blue; } .swiper-box{ display: block; width: 86%; height: 600px; margin: 20rpx 7%; } .lines{ display: flex; display: -webkit-flex; width: 100%; border-bottom: 1px solid #ccc; } .lines_text{ width: 30%; height: 100rpx; line-height: 100rpx; } .lines_inp{width: 70%;} .lines_inp input{ width: 100%; height: 100rpx; line-height: 100rpx; } .btns{ width: 98%; margin: 100rpx 1% 0; background: rgba(100,100,255,0.5); }
3、JS
Page({ data: { msg: [], currentTab: 0, winWidth: 0, winHeight: 0 }, onLoad: function () { var that = this; wx.getSystemInfo( { success: function( res ) { that.setData( { winWidth: res.windowWidth, winHeight: res.windowHeight }); } }); that.setData({ msg: [ { "name":"注册", "mykey":0 // "inputName": // ["真实姓名","手机号码","昵称","密码","确认密码"] }, { "name":"登录", "mykey":1 // "inputName":["用户名","密码"] } ] }); }, switchNav: function (e) { var that = this; that.setData({ currentTab: e.target.dataset.current }) }, bindchange: function (e) { var that = this; that.setData({ currentTab: e.detail.current }) }, register: function () { } })
相关文章推荐
- 微信小程序例子——使用swiper组件实现图片切换
- 微信小程序实现tab和swiper切换结合效果
- 微信小程序实现tab和swiper切换结合效果viewpage+tab效果
- 微信小程序之swiper制作tab切换效果
- 微信小程序 swiper制作tab切换实现附源码
- 微信小程序实现简易版tab切换效果
- 微信小程序之tab切换效果
- 转载【微信小程序】:微信小程序滚动Tab选项卡:左右可滑动切换(仿某宝)
- 微信小程序滚动Tab选项卡:左右可滑动切换
- 微信小程序组件swiper结合模板的使用
- 微信小程序中多个button/view组件中进行切换时改变样式
- 微信小程序实现tab切换效果
- [微信小程序]根据图片宽高动态改变swiper(轮播图)组件宽高
- 微信小程序中多个button/view组件中进行切换时改变样式
- 微信小程序中的swiper组件
- 微信小程序实用组件:城市切换
- 微信小程序开发(五)-类似于tab切换
- 【微信小程序笔记-3】组件-视图容器(ScrollView和Swiper)
- 学习微信小程序--组件(swiper)
- 微信小程使用swiper组件实现图片轮播切换显示功能【附源码下载】