小程序?qū)崿F(xiàn)tab標簽頁
更新時間:2020年11月16日 09:30:33 作者:路癡不臉盲
這篇文章主要為大家詳細介紹了小程序?qū)崿F(xiàn)tab標簽頁,可點擊切換,滑動切換頁面,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了小程序?qū)崿F(xiàn)tab標簽頁的具體代碼,供大家參考,具體內(nèi)容如下
頁面效果:
HTML:
<view wx:if="{{userType==0}}" style="height:100%"> <view class="tab_box" style="width: 100%"> <view class="tabs_v"> <block wx:for="{{tabs}}" wx:for-item="item" wx:key="index"> <view class="tab_v {{index<1?'tab_nature':'tab_course'}}" bindtap='changeCurrentTab_' data-index='{{index}}' data-current='{{index}}'> <text class="tab_txt {{currentTab==index? 'tab_v_active' : ''}}">{{item.label}}</text> </view> </block> </view> </view> <!-- tab 容器 --> <view class="tabWrap"> <swiper class="" current="{{currentTab}}" duration="300" bindchange="swiperTab" style="width:100%;height:100%;"> <!-- 頁面1 --> <block> <swiper-item style="width:100%;height:100%;"> <view class="" style="width:100%;height:100%;"> <scroll-view style="width:100%;height:100%;" scroll-y="true" bindscrolltolower='scrollToLower' bindscrolltoupper='scrollToUpper' lower-threshold='30' upper-threshold='30'> <view style="width:100%;height:auto;"> 頁面1 </view> </scroll-view> </view> </swiper-item> </block> <!-- 頁面2 --> <block> <swiper-item style="width:100%;height:100%;"> <view class="" style="width:100%;height:100%;"> <scroll-view style="width:100%;height:100%;" scroll-y="true" bindscrolltolower='scrollToLower' bindscrolltoupper='scrollToUpper' lower-threshold='30' upper-threshold='30'> <view style="width:100%;height:auto;"> 頁面2 </view> </scroll-view> </view> </swiper-item> </block> </swiper> </view> </view>
CSS:
/* tab */ .tab_box{ height: 50px; display: flex; flex-direction: row; background-color: #fff; border-bottom: 1px solid #E5E5E5; margin-bottom: 15px; } .tabs_v{ width: 100%; display: flex; flex-direction: row; justify-content: space-between; align-items: center; } .tab_v{ width: 50%; text-align: center; } .tab_txt{ border-bottom: 2px solid transparent; padding-bottom: 14px; color: #999999; } .tab_v_active{ border-bottom: 2px solid #00C6AC; color: #00C6AC; font-weight: bold; } /* 容器 */ .tabWrap{ width: 100%; height: calc(100% - 67px); position: relative; border-bottom: 1px solid #e6e6e6; }
JS:
Page({ /** * 頁面的初始數(shù)據(jù) */ data: { tabs: [ {label:'訪客', index: 0}, {label:'工作人員', index: 1} ], currentTab:0 }, /** * 生命周期函數(shù)--監(jiān)聽頁面加載 */ onLoad: function (options) { }, /** * 生命周期函數(shù)--監(jiān)聽頁面初次渲染完成 */ onReady: function () { }, /** * 生命周期函數(shù)--監(jiān)聽頁面顯示 */ onShow: function () { }, // tab切換 changeCurrentTab_(e){ let that = this if (that.data.currentTab === e.currentTarget.dataset.current){ return false }else{ that.setData({ currentTab: e.currentTarget.dataset.current }) } }, //滑動切換 swiperTab: function (e) { var that = this; that.setData({ currentTab: e.detail.current }); } })
為大家推薦現(xiàn)在關注度比較高的微信小程序教程一篇:《微信小程序開發(fā)教程》小編為大家精心整理的,希望喜歡。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- 微信小程序?qū)崿F(xiàn)動態(tài)改變view標簽寬度和高度的方法【附demo源碼下載】
- 微信小程序?qū)崿F(xiàn)點擊按鈕修改view標簽背景顏色功能示例【附demo源碼下載】
- 微信小程序使用scroll-view標簽實現(xiàn)自動滑動到底部功能的實例代碼
- 微信小程序 <swiper-item>標簽傳入數(shù)據(jù)
- 微信小程序基于slider組件動態(tài)修改標簽透明度的方法示例
- 微信小程序?qū)崿F(xiàn)點擊按鈕移動view標簽的位置功能示例【附demo源碼下載】
- 微信小程序button標簽open-type屬性原理解析
- 微信小程序 基礎知識css樣式media標簽
- 如何去除富文本中的html標簽及vue、react、微信小程序中的過濾器
- 微信小程序中input標簽詳解及簡單實例
相關文章
前端實現(xiàn)文本超出指定行數(shù)顯示"展開"和"收起"效果詳細步驟
本文介紹如何使用JavaScript原生代碼實現(xiàn)文本折疊展開效果,并提供方法指導如何在Vue或React等框架中修改實現(xiàn),詳細介紹了創(chuàng)建整體框架、設置樣式及利用JS控制元素的步驟,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2024-10-10讓JavaScript擁有類似Lambda表達式編程能力的方法
在前幾天的博文中我發(fā)布了一個可以自定義頁碼呈現(xiàn)方式的組件,有C#和JavaScript兩個版本。2010-09-09javascript函數(shù)以及基礎寫法100多條實用整理
100多個很有用的JavaScript函數(shù)以及基礎寫法匯總,在項目開發(fā)中經(jīng)常會使用到,本文整理了一些,希望對你們有幫助2013-01-01