搜尋
首頁微信小程式小程式開發關於微信小程式實作頂部選項卡(swiper)的介紹

關於微信小程式實作頂部選項卡(swiper)的介紹

Jun 27, 2018 pm 02:13 PM
swiper微信小程式選項卡

這篇文章主要為大家詳細介紹了微信小程式實現頂部選項卡效果,具有一定的參考價值,有興趣的小夥伴們可以參考一下

微信小程式頂部選項卡在開發中是非常常用的,下面用一點時間實現了一下。

效果圖:

#下面直接上程式碼:

wxml:

<!--pages/index/index.wxml--> 
<view class="swiper-tab"> 
 <view class="tab-item {{currentTab==0 ? &#39;on&#39; : &#39;&#39;}}" data-current="0" bindtap="swichNav">选项一</view> 
 <view class="tab-item {{currentTab==1 ? &#39;on&#39; : &#39;&#39;}}" data-current="1" bindtap="swichNav">选项二</view> 
 <view class="tab-item {{currentTab==2 ? &#39;on&#39; : &#39;&#39;}}" data-current="2" bindtap="swichNav">选项三</view> 
</view> 
 
<swiper current="{{currentTab}}" class="swiper" duration="300" style="height:{{winHeight - 30}}px" bindchange="bindChange"> 
 <swiper-item> 
  <view>页面一</view> 
 </swiper-item> 
 <swiper-item> 
  <view>页面二</view> 
 </swiper-item> 
 <swiper-item> 
  <view>页面三</view> 
 </swiper-item> 
</swiper>

wxss:

#
/* pages/index/index.wxss */ 
.swiper-tab{ 
 width: 100%; 
 text-align: center; 
 line-height: 80rpx; 
 border-bottom: 1px solid #000; 
 display: flex; 
 flex-direction: row; 
 justify-content: center; 
} 
.tab-item{ 
 flex: 1; 
 font-size: 30rpx; 
 display: inline-block;  
 color: #777777; 
} 
.on{ 
 color: red; 
 border-bottom: 5rpx solid red; 
} 
.swiper{ display: block; height: 100%; width: 100%; overflow: hidden; } 
.swiper view{ 
 text-align: center; 
 padding-top: 100rpx; 
}

js:

// pages/index/index.js 
Page({ 
 
 /** 
  * 页面的初始数据 
  */ 
 data: { 
  winWidth:0, 
  winHeight:0, 
  currentTab:0 
 }, 
 
 /** 
  * 生命周期函数--监听页面加载 
  */ 
 onLoad: function (options) { 
  var that = this; 
 
  /** 
   * 获取系统信息 
   */ 
  wx.getSystemInfo({ 
 
   success: function (res) { 
    that.setData({ 
     winWidth: res.windowWidth, 
     winHeight: res.windowHeight 
    }); 
   } 
 
  }); 
 }, 
 bindChange: function (e) { 
 
  var that = this; 
  that.setData({ currentTab: e.detail.current }); 
 
 }, 
 swichNav: function (e) { 
 
  var that = this; 
 
  if (this.data.currentTab === e.target.dataset.current) { 
   return false; 
  } else { 
   that.setData({ 
    currentTab: e.target.dataset.current 
   }) 
  } 
 } , 
 /** 
  * 页面相关事件处理函数--监听用户下拉动作 
  */ 
 onPullDownRefresh: function () { 
 
 }, 
 
 /** 
  * 页面上拉触底事件的处理函数 
  */ 
 onReachBottom: function () { 
 
 }, 
 
 /** 
  * 用户点击右上角分享 
  */ 
 onShareAppMessage: function () { 
 
 } 
})

以上是實現過程,整體沒什麼難度。可以參考參考。

以上就是本文的全部內容,希望對大家的學習有所幫助,更多相關內容請關注PHP中文網!

相關推薦:

微信小程式實作導覽列標籤的效果

微信小程式商城中側邊欄分類的效果實作

微信小程式中選項卡的範例

以上是關於微信小程式實作頂部選項卡(swiper)的介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!