本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)tab左右切換展示的具體代碼,供大家參考,具體內(nèi)容如下
為花山等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計(jì)制作服務(wù),及花山網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、花山網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會(huì)得到認(rèn)可,從而選擇與我們長(zhǎng)期合作。這樣,我們也可以走得更遠(yuǎn)!
分析
1、設(shè)置data-current屬性用于:點(diǎn)擊當(dāng)前項(xiàng)時(shí),通過點(diǎn)擊事件swichNav中處理e.dataset.current取到點(diǎn)擊的目標(biāo)值。
2、swiper組件的current組件用于控制當(dāng)前顯示哪一頁
3、swiper組件綁定change事件switchTab,通過e.detail.current拿到當(dāng)前頁
wxml:
<view class="record-box">
<view class="nav">
<scroll-view scroll-x="true" class="navbar-box" srcoll-left="{{navScrollLeft}}"
srcoll-width-animation="{{true}}">
<block wx:for="{{recordMain}}" wx:for-index="idx" wx:for-item="navItem" wx:key="idx">
<view class="nav-item {{currentTab == idx ? 'text' : ''}}" data-current="{{idx}}"
bindtap="switchNav">
<label>{{navItem.text}}</label>
</view>
</block>
</scroll-view>
</view>
</view>
------------------------------------------------
<view class="record-ft">
<swiper class="tab-box" current="{{currentTab}}" duration="300" bindchange="switchTab">
<swiper-item wx:for="{{[0,1,2,3]}}" wx:for-item="tabItem" wx:for-index="idx" wx:key="idx"
class="tab-cnetent">
<block wx:for="{{tabContent}}" wx:for-item="tabItem" wx:key=" ">
<view class="padding-box" bindtap="navigateUrl" data-url="/pages/index/index">
<view class="weui-list-box weui-main">
<view class="weui-list-bd">
<view class="img-box">
<image src="{{tabItem}}" class="img" mode="widthFix"></image>
</view>
</view>
<view class="weui-list-ft">
<view class="weui-title">
<view class="text-flow clamp-xs font-sm">{{tabItem.title}}</view>
<view class="text">
<laber>{{tabItem.text}}</laber>
<laber>{{tabItem.text}}</laber>
</view>
</view>
<view class="weui-cost">
<view>¥<laber>{{tanItem.cost}}</laber></view>
</view>
</view>
</view>
</view>
</block>
</swiper-item>
</swiper>
</view>JS
Page ({
const app = getApp()
data: {
recordMian: [
{
title: "插畫藝術(shù)"
},
{
title: "工藝作品"
},
{
title: "服裝藝術(shù)"
},
{
title: "三維建模"
},
],
tabContent: [
{
title: "臺(tái)燈臥室床頭 簡(jiǎn)約現(xiàn)代書房 北歐宜家創(chuàng)意裝飾個(gè)性圓球臺(tái)燈床頭燈",
text: "臺(tái)燈",
cost: "1255",
imgUrl: "http://img.weiye.me/zcimgdir/album/file_59b8f7b66ba7f.jpg",
},
{
title: "雪域冰雪天地8寸牛乳芝士蛋糕",
text: "蛋糕",
cost: "15",
imgUrl: "http://img.weiye.me/zcimgdir/album/file_59b8f7b66ba7f.jpg",
},
],
currentTab: 0,
navScrollLeft: 0
},
// 事件處理函數(shù)
onLoad: function() {
// 控制record-box隨鼠標(biāo)切換調(diào)整位置
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo,
hasUserInfo: true
})
} else if (this.data.canIUse) {
app.userInfoReadyCallback = res => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
}
else {
wx.getUserInfo({
success: res => {
app.globalData.userInfo = res.userInfo
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
}
wx.getSystemInfo({
success: (res) => {
this.setData({
pixelRatio: res.pixelRatio,
windowHeight: res.windowHeight,
windowWidth: res.windowWidth
})
}
})
},
// 滑動(dòng)事件
// 點(diǎn)擊標(biāo)題切換當(dāng)前頁時(shí)改變樣式
switchNav(event) {
var cur = event.currentTarget.dataset.current;
if (this.data.currentTab == cur) {
return false;
} else {
this.setData({
currentTab: cur
})
}
},
// 滾動(dòng)切換標(biāo)簽樣式
switchTab(event) {
var cur = evnet.detail.current;
var singeNavWidth = this.data.windowWidth / 5;
this.setData({
currentTab: cur,
navScrollLeft: (cur - 2) * singleNavWidth
});
}
})效果圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
本文標(biāo)題:微信小程序?qū)崿F(xiàn)tab左右切換效果
URL地址:http://chinadenli.net/article42/phojhc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、標(biāo)簽優(yōu)化、移動(dòng)網(wǎng)站建設(shè)、商城網(wǎng)站、網(wǎng)站設(shè)計(jì)公司、品牌網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)