小程序?qū)崿F(xiàn)頁(yè)面頂部選項(xiàng)卡效果
本文實(shí)例為大家分享了小程序?qū)崿F(xiàn)選項(xiàng)卡效果的具體代碼,供大家參考,具體內(nèi)容如下
效果圖:
github源碼下載
<!--index.wxml--> <view class="swiper-tab" > <view bindtap="swithNav" wx:for="{{tabCont}}" wx:key="item.index" class="swiper-tab-list {{currentTab==item.index?'active':''}}" data-current='{{item.index}}' >{{item.title}}</view> </view> <swiper class="swiper-box" current="{{currentTab}}" duration="300" style="height:400px" bindchange="GetCurrentTab" data-current='6' > <swiper-item wx:for="{{tabCont}}" wx:key="item.index"> <image src='{{item.pic}}'></image> <view>{{item.title}}</view> </swiper-item> </swiper>
CSS:
/**index.wxss**/ /**index.wxss**/ .swiper-tab { line-height: 80rpx; border: 1px solid #ccc; display: flex; justify-content: space-around; align-items: center; } .swiper-tab-list { font-size: 30rpx; color: #777; text-align: center; } .active { color: #da7c0c; border-bottom: 5rpx solid #da7c0c; } .swiper-box { display: block; height: 100%; width: 100%; overflow: hidden; } .swiper-box view { text-align: center; } image { width: 100%; }
js:
Page({ /** * 頁(yè)面的初始數(shù)據(jù) */ data: { currentTab:0, tabCont: [{ "title": "tab1", "pic": "../../img/1.jpg", "index": "0" }, { "title": "tab2", "pic": "../../img/2.jpg", "index": "1" }, { "title": "tab3", "pic": "../../img/3.jpg", "index": "2" }, { "title": "tab4", "pic": "../../img/2.jpg", "index": "3" }, { "title": "tab5", "pic": "../../img/2.jpg", "index": "4" }, { "title": "tab6", "pic": "../../img/2.jpg", "index": "5" }, { "title": "tab7", "pic": "../../img/2.jpg", "index": "6" }, { "title": "tab8", "pic": "../../img/2.jpg", "index": "7" }, { "title": "tab9", "pic": "../../img/2.jpg", "index": "8" }], }, /** * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載 */ onLoad: function (options) { }, /** * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面初次渲染完成 */ onReady: function () { }, /** * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面顯示 */ onShow: function () { }, /** * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面隱藏 */ onHide: function () { }, /** * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面卸載 */ onUnload: function () { }, /** * 頁(yè)面相關(guān)事件處理函數(shù)--監(jiān)聽(tīng)用戶下拉動(dòng)作 */ onPullDownRefresh: function () { }, /** * 頁(yè)面上拉觸底事件的處理函數(shù) */ onReachBottom: function () { }, /** * 用戶點(diǎn)擊右上角分享 */ onShareAppMessage: function () { }, // swiper滑動(dòng)時(shí)觸發(fā)bindchange事件,獲取事件對(duì)象e獲取當(dāng)前所在滑塊的 index,并將其更新至data的currentTab中,視圖渲染通過(guò)判斷currentTab的讓對(duì)應(yīng)的tab hover。 GetCurrentTab:function(e){ console.log(e.detail.current); var that = this; this.setData({ currentTab:e.detail.current }); // console.log("11111"+this.data.currentTab); }, swithNav:function(e){ var that = this; that.setData({ currentTab:e.target.dataset.current }); } })
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序?qū)崿F(xiàn)選項(xiàng)卡效果
- 微信小程序自定義組件實(shí)現(xiàn)tabs選項(xiàng)卡功能
- 微信小程序?qū)崿F(xiàn)導(dǎo)航欄選項(xiàng)卡效果
- 微信小程序?qū)崿F(xiàn)選項(xiàng)卡功能
- 微信小程序之選項(xiàng)卡的實(shí)現(xiàn)方法
- 微信小程序?qū)崿F(xiàn)頂部普通選項(xiàng)卡效果(非swiper)
- 微信小程序?qū)崿F(xiàn)頂部選項(xiàng)卡(swiper)
- 微信小程序 選項(xiàng)卡的簡(jiǎn)單實(shí)例
- 微信小程序?qū)崙?zhàn)之頂部導(dǎo)航欄(選項(xiàng)卡)(1)
- 微信小程序開(kāi)發(fā)之選項(xiàng)卡(窗口底部TabBar)頁(yè)面切換
- 微信小程序 tabs選項(xiàng)卡效果的實(shí)現(xiàn)
- 微信小程序開(kāi)發(fā)之實(shí)現(xiàn)選項(xiàng)卡(窗口頂部TabBar)頁(yè)面切換
- 微信小程序 實(shí)現(xiàn)tabs選項(xiàng)卡效果實(shí)例代碼
相關(guān)文章
JS中超越現(xiàn)實(shí)的匿名函數(shù)用法實(shí)例分析
這篇文章主要介紹了JS中超越現(xiàn)實(shí)的匿名函數(shù)用法,結(jié)合實(shí)例形式分析了javascript匿名函數(shù)定義、用法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2019-06-06微信分享的標(biāo)題、縮略圖、連接及描述設(shè)置方法
微信分享的標(biāo)題、縮略圖、連接及描述該如何設(shè)置,這個(gè)問(wèn)題確實(shí)難道不少朋友,下面有個(gè)示例,大家可以看看2014-10-10input file的默認(rèn)value清空與賦值方法
出于安全性考慮,JS是不能直接設(shè)置File的value值的,下面是我總結(jié)出來(lái)的方法2010-09-09ie9 提示''console'' 未定義問(wèn)題的解決方法
關(guān)掉開(kāi)發(fā)者工具之后,在狀態(tài)欄發(fā)現(xiàn)提示'console' 未定義,為什么之前的運(yùn)行沒(méi)有問(wèn)題,之后的就不行呢2014-03-03JS實(shí)現(xiàn)三個(gè)層重疊點(diǎn)擊互相切換的方法
這篇文章主要介紹了JS實(shí)現(xiàn)三個(gè)層重疊點(diǎn)擊互相切換的方法,涉及JavaScript動(dòng)態(tài)操作頁(yè)面定位屬性的相關(guān)技巧,需要的朋友可以參考下2015-10-10獲取URL地址中的文件名和參數(shù)的javascript代碼
JS 獲取URL地址中的文件名和參數(shù),這個(gè)版本中有詳細(xì)的注釋。2009-09-09