小程式標籤頁切換效果
效果:
.wxml
<view class='topTabSwiper'>
<view class='tab {{currentData == 0 ? "tabBorer" : ""}}' data-current="0" bindtap='checkCurrent'>達叔</view>
<view class='tab {{currentData == 1 ? "tabBorer" : ""}}' data-current="1" bindtap='checkCurrent'>達叔</view>
<view class='tab {{currentData == 2 ? "tabBorer" : ""}}' data-current="2" bindtap='checkCurrent'>達叔</view>
</view>
<swiper current="{{currentData}}" class='swiper' style="height:600px;" duration="300" bindchange="bindchange">
<swiper-item>
<view class='swiper_con'>welcome come to 達叔</view>
</swiper-item>
<swiper-item>
<view class='swiper_con'>welcome come to 達叔</view>
</swiper-item>
<swiper-item>
<view class='swiper_con'>welcome come to 達叔</view>
</swiper-item>
</swiper>
複製程式碼
.wxss
.tab {
float: left;
width: 33.3333%;
text-align: center;
padding: 10rpx 0;
}
.topTabSwiper {
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
zoom: 1;
}
.topTabSwiper:after {
content: "";
clear: both;
display: block;
}
.tabBorer {
border-bottom: 1px solid #f00;
color: #f00;
}
.swiper {
width: 100%;
}
.swiper_con {
text-align: center;
width: 100%;
height: 100%;
padding: 80rpx 0;
}
/* */
.person_box {
position: relative;
}
.phone_select {
margin-top: 0;
z-index: 100;
position: absolute;
}
.select_one {
text-align: center;
background-color: rgb(239, 239, 239);
width: 676rpx;
height: 100rpx;
line-height: 100rpx;
margin: 0 5%;
border-bottom: 2rpx solid rgb(255, 255, 255);
}
複製程式碼
.js
Page({
/**
* 頁面的初始資料
*/
data: {
currentData: 0,
selectPerson: true,
},
/**
* 生命週期函式--監聽頁面載入
*/
onLoad: function(options) {},
//獲取當前滑塊的index
bindchange: function(e) {
const that = this;
that.setData({
currentData: e.detail.current
})
},
//點選切換,滑塊index賦值
checkCurrent: function(e) {
const that = this;
if (that.data.currentData === e.target.dataset.current) {
return false;
} else {
that.setData({
currentData: e.target.dataset.current
})
}
}
})
複製程式碼
效果:
.wxml
<view class="head">
<view class="head_item {{selected?'head_itemActive':''}}" bindtap="selected">個人</view>
<view class="ring"></view>
<view class="head_item {{selected1?'head_itemActive':''}}" bindtap='selected1'>設定</view>
</view>
<view class="main {{selected?'show':'hidden'}}">
</view>
<view class="main {{selected1?'show':'hidden'}}">
<text>達叔</text>
</view>
複製程式碼
.wxss
page {
background-color: rgba(239, 239, 240, 1);
}
.text {
position: absolute;
top: 380rpx;
left: 356rpx;
}
.canvas {
width: 100%;
height: 550rpx;
margin: 30rpx;
}
.head_item {
width: 374rpx;
text-align: center;
font-size: 34rpx;
color: #999;
letter-spacing: 0;
}
.head_itemActive {
color: rgba(87, 213, 200, 1);
}
.ring {
width: 2rpx;
height: 100%;
background-color: rgba(204, 204, 204, 1);
}
.head {
width: 100%;
height: 100rpx;
background-color: rgba(255, 255, 255, 1);
border-bottom: 1rpx solid rgba(204, 204, 204, 1);
display: flex;
align-items: center;
justify-content: space-between;
position: fixed;
top: 0;
z-index: 10;
}
.main {
position: absolute;
width: 100%;
height: 100%;
display: block;
box-sizing: border-box;
padding-top: 100rpx;
top: 0;
}
.show {
display: block;
text-align: center;
}
.hidden {
display: none;
text-align: center;
}
複製程式碼
.js
//index.js
var wxCharts = require('../../utils/wxcharts-min.js');
const app = getApp();
var ringChart = null;
Page({
data: {
selected: true,
selected1: false
},
torecord() {
wx.navigateBack({
delta: 1,
})
},
onLoad: function (e) {
// 高度自適應
var windowWidth = '', windowHeight = ''; //定義寬高
try {
var res = wx.getSystemInfoSync(); //試圖獲取螢幕寬高資料
windowWidth = res.windowWidth / 750 * 690; //以設計圖750為主進行比例算換
windowHeight = res.windowWidth / 750 * 550 //以設計圖750為主進行比例算換
} catch (e) {
console.error('getSystemInfoSync failed!'); //如果獲取失敗
}
ringChart = new wxCharts({
canvasId: "ringCanvas",
type: "ring",
series: [
{ data: 20, },
{ data: 30, },
{ data: 60, }
],
width: windowWidth,
height: windowHeight,
dataLabel: false,
legend: false,
});
},
selected: function (e) {
this.setData({
selected1: false,
selected: true
})
},
selected1: function (e) {
this.setData({
selected: false,
selected1: true
})
}
})
複製程式碼
達叔小生:往後餘生,唯獨有你 You and me, we are family ! 90後帥氣小夥,良好的開發習慣;獨立思考的能力;主動並且善於溝通 簡書部落格: 達叔小生 www.jianshu.com/u/c785ece60…
結語
- 下面我將繼續對 其他知識 深入講解 ,有興趣可以繼續關注
- 小禮物走一走 or 點贊