微信小程序?qū)崿F(xiàn)tab和swiper切換結(jié)合效果
本文實(shí)例為大家分享了小程序?qū)崿F(xiàn)tab和swiper切換效果展示的具體代碼,供大家參考,具體內(nèi)容如下
先上效果圖:

實(shí)現(xiàn)代碼如下:
wxml頁面
<scroll-view scroll-x="true" class="weui-navbar">
<block wx:for-items="{{tabs}}">
<view id="{{index}}" class="{{activeIndex == index ?'item_on':''}} default-item" bindtap="tabClick" style="width:{{tabW}}px">
{{item}}
</view>
</block>
<view class="weui-navbar-slider" style="transform:translateX({{slideOffset}}px);"></view>
</scroll-view>
<view class="rec" />
<swiper current="{{activeIndex}}" class="swiper-box" duration="100" bindchange="bindChange">
<swiper-item class="swiper-item">
<view class="slide-view">tab0</view>
</swiper-item>
<swiper-item class="swiper-item">
<view class="slide-view">tab1</view>
</swiper-item>
<swiper-item class="swiper-item">
<view class="slide-view">tab2</view>
</swiper-item>
<swiper-item class="swiper-item">
<view class="slide-view">tab3</view>
</swiper-item>
<swiper-item class="swiper-item">
<view class="slide-view">tab4</view>
</swiper-item>
<swiper-item class="swiper-item">
<view class="slide-view">tab5</view>
</swiper-item>
<swiper-item class="swiper-item">
<view class="slide-view">tab6</view>
</swiper-item>
</swiper>
wxss樣式:
page {
height: 100%;
}
view , scroll-view{
padding: 0px;
margin: 0px;
}
.weui-navbar{
width: 100%;
position: fixed;
border-bottom: 1px solid #00bba1;
box-sizing: border-box;
white-space: nowrap;
z-index: 100;
background: white;
}
.rec{
width: 100%;
height: 7%;
}
.weui-navbar .default-item{
/*width:25%;*/
display: inline-block;
text-align: center;
font-size: 32rpx;
box-sizing: border-box;
height: 7%;
padding-bottom: 20rpx;
}
.weui-navbar .item_on{
color: #00bba1;
}
.weui-navbar-slider{
position: absolute;
width: 160rpx;
height: 2px;
content:"";
background: #00bba1;
bottom: 0px;
left: 12.5rpx;
transition: transform .3s;
}
.swiper-box{
height: 900px;
border-bottom: 1px solid #d1d1d1;
}
.swiper-box .swiper-item{
text-align: center;
padding-top: 200rpx;
height: 100%;
}
js代碼:
//index.js
//獲取應(yīng)用實(shí)例
var app = getApp();
var mtabW;
Page({
data: {
tabs:["綜合與繪畫","藝術(shù)噴漆","泥塑","紙面繪畫","布面繪畫","中國油畫","水墨畫"],
activeIndex:0,
slideOffset:0,
tabW:0
},
//事件處理函數(shù)
onLoad: function () {
var that = this;
wx.getSystemInfo({
success: function (res) {
mtabW = res.windowWidth / 4; //設(shè)置tab的寬度
that.setData({
tabW:mtabW
})
}
});
},
bindViewTap: function() {
wx.navigateTo({
url: '../logs/logs'
})
},
tabClick:function(e){
var that = this;
var idIndex = e.currentTarget.id;
var offsetW = e.currentTarget.offsetLeft; //2種方法獲取距離文檔左邊有多少距離
this.setData({
activeIndex:idIndex,
slideOffset:offsetW
});
},
bindChange:function(e){
var current = e.detail.current;
if((current+1)%4 == 0){
}
var offsetW = current * mtabW; //2種方法獲取距離文檔左邊有多少距離
this.setData({
activeIndex:current,
slideOffset:offsetW
});
}
})
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序開發(fā)之實(shí)現(xiàn)選項(xiàng)卡(窗口頂部TabBar)頁面切換
- 微信小程序?qū)崿F(xiàn)tab左右切換效果
- 微信小程序 Tab頁切換更新數(shù)據(jù)
- 微信小程序 swiper制作tab切換實(shí)現(xiàn)附源碼
- 微信小程序開發(fā)之選項(xiàng)卡(窗口底部TabBar)頁面切換
- 微信小程序?qū)崿F(xiàn)tab切換效果
- 微信小程序滾動(dòng)Tab實(shí)現(xiàn)左右可滑動(dòng)切換
- 微信小程序?qū)崿F(xiàn)tab頁面切換功能
- 微信小程序開發(fā)實(shí)現(xiàn)的選項(xiàng)卡(窗口頂部/底部TabBar)頁面切換功能圖文詳解
- 微信小程序?qū)崿F(xiàn)tab頁面切換效果
相關(guān)文章
鴻蒙系統(tǒng)中實(shí)現(xiàn)圖片上傳功能全流程
在鴻蒙系統(tǒng)中實(shí)現(xiàn)圖片上傳功能,整體流程可以類比為?“選快遞→填單→發(fā)貨→簽收”?的過程,下面給大家介紹鴻蒙系統(tǒng)中實(shí)現(xiàn)圖片上傳功能全流程,感興趣的朋友一起看看吧2025-04-04
前端Webpack配置之eval-source-map使用方法
eval-source-map 是 Webpack 中 devtool 選項(xiàng)的一種模式,它提供了一種內(nèi)聯(lián) Source Map 的方式,用于開發(fā)環(huán)境中的源代碼映射,這篇文章主要介紹了前端Webpack配置之eval-source-map使用方法,需要的朋友可以參考下2024-12-12
js 開發(fā)之a(chǎn)utocomplete="off"在chrom中失效的解決辦法
這篇文章主要介紹了js 開發(fā)之a(chǎn)utocomplete="off"在chrom中失效的解決辦法的相關(guān)資料,希望通過本文能幫助到大家,解決遇到這樣的問題,需要的朋友可以參考下2017-09-09
Javascript模擬實(shí)現(xiàn)new原理解析
這篇文章主要介紹了Javascript模擬實(shí)現(xiàn)new原理解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-03-03
javascript中href和replace的比較(詳解)
下面小編就為大家?guī)硪黄猨avascript中href和replace的比較(詳解)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-11-11
var?let?const關(guān)鍵字之間的區(qū)別及使用場(chǎng)景示例詳解
這篇文章主要為大家介紹了var?let?const關(guān)鍵字之間的區(qū)別及使用場(chǎng)景示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-12-12

