微信小程序?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ù)噴漆","泥塑","紙面繪畫","布面繪畫","中國(guó)油畫","水墨畫"], 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)文章
JS中的Replace()傳入函數(shù)時(shí)的用法詳解
這篇文章主要介紹了JS中的Replace()傳入函數(shù)時(shí)的用法詳解,replace方法的語法是:stringObj.replace(rgExp, replaceText)關(guān)于js replace 傳入函數(shù)的用法,大家通過本文學(xué)習(xí)吧2017-09-09uni-app微信小程序登錄并使用vuex存儲(chǔ)登錄狀態(tài)的思路詳解
這篇文章主要介紹了uni-app微信小程序登錄并使用vuex存儲(chǔ)登錄態(tài)的思路,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-11-11javascript 初學(xué)教程及五子棋小程序的簡(jiǎn)單實(shí)現(xiàn)
下面小編就為大家?guī)硪黄猨avascript 初學(xué)教程及五子棋小程序的簡(jiǎn)單實(shí)現(xiàn)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-07-07微信小程序發(fā)送短信驗(yàn)證碼完整實(shí)例
這篇文章主要介紹了微信小程序發(fā)送短信驗(yàn)證碼完整實(shí)例,實(shí)現(xiàn)發(fā)送短信驗(yàn)證碼,帶60秒倒計(jì)時(shí)功能,無需服務(wù)器端,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2019-01-01js中動(dòng)態(tài)創(chuàng)建json,動(dòng)態(tài)為json添加屬性、屬性值的實(shí)例
下面小編就為大家?guī)硪黄猨s中動(dòng)態(tài)創(chuàng)建json,動(dòng)態(tài)為json添加屬性、屬性值的實(shí)例。小編覺的挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-12-12JavaScript前端面試扁平數(shù)據(jù)轉(zhuǎn)tree與tree數(shù)據(jù)扁平化
這篇文章主要為大家介紹了JavaScript面試中扁平數(shù)據(jù)轉(zhuǎn)tree以及tree數(shù)據(jù)扁平化示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06uni-app小程序中父組件和子組件傳值的實(shí)現(xiàn)實(shí)例
uniapp父子組件引用傳值,和vue的一樣,沒有小程序那樣的麻煩,下面這篇文章主要給大家介紹了關(guān)于uni-app小程序中父組件和子組件傳值的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08