




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
第小程序?qū)崿F(xiàn)頁面多級來回切換的示例代碼目錄第一步第二步全部完整代碼wxmljscss
第一步
首先通過swiper創(chuàng)建一個簡單的多tab頁面
通過觸發(fā)pagechange1方法中的事件對currentIndex來進(jìn)行賦值,又通過currentIndex的改變使前端wxml對應(yīng)更改,這個部分對滑動和點(diǎn)擊的操作都一樣,無非就是使currentIndex對應(yīng)到各自的位置,通過數(shù)字來決定位置
//滑動
pagechange1:function(ee){
if("touch"===ee.detail.source){
letcurrentPageIndex=this.data.currentIndex;
currentPageIndex=(currentPageIndex+1)%2;
this.setData({
currentIndex:currentPageIndex,
//點(diǎn)擊tab時(shí)觸發(fā)
titleClick:function(e){
this.setData({
//拿到當(dāng)前索引并動態(tài)改變
currentIndex:e.currentTarget.dataset.idx
這個部分完整代碼如下:
wxml
view
!--Tab布局--
view
viewbindtap='titleClick'data-idx='0'
textclass="{{0==currentIndex'fontColorBox':''}}"安卓/text
hrclass="{{0==currentIndex'lineBox':'notLineBox'}}"/
/view
viewbindtap='titleClick'data-idx='1'
textclass="{{1==currentIndex'fontColorBox1':''}}"蘋果/text
hrclass="{{1==currentIndex'lineBox':'notLineBox'}}"/
/view
/view
!--內(nèi)容布局--
swiperbindchange='pagechange1'current='{{currentIndex}}'
swiper-item
view內(nèi)容1/view
/swiper-item
swiper-item
view內(nèi)容2/view
/swiper-item
/swiper
/view
wxss
Page{
/*全局樣式*/
background:rgb(244,245,249);
height:100%;
position:fixed;
.fontColorBox,
.fontColorBox1{
/*文字默認(rèn)顏色*/
color:black;
.navBox{
/*頂部tab盒子樣式*/
width:100%;
height:108rpx;
background:white;
display:flex;
align-items:center;
justify-content:center;
.navBoxview:last-child{
/*最后一個tab標(biāo)題的樣式*/
padding-left:20%;
.titleBox{
/*未選中文字的樣式*/
color:rgb(168,170,175);
font-size:30rpx;
display:flex;
flex-direction:column;
align-items:center;
.lineBox,.notLineBox{
/*選中及未選中底線共同樣式*/
width:32rpx;
height:8rpx;
.lineBox{
/*選中底線樣式*/
background:rgb(43,44,45);
margin-top:16rpx;
border-radius:4rpx;
.notLineBox{
/*未選中底線樣式*/
background:transparent;
.swiperTtemBox{
/*底部內(nèi)容樣式*/
height:100vh;
overflow:scroll;
margin:12rpx0rpx;
background:white;
font-size:28rpx;
js
constapp=getApp()
Page({
data:{
currentIndex:0,//默認(rèn)第一個
pagechange1:function(ee){
if("touch"===ee.detail.source){
letcurrentPageIndex=this.data.currentIndex;
currentPageIndex=(currentPageIndex+1)%2;
this.setData({
currentIndex:currentPageIndex,
//點(diǎn)擊tab時(shí)觸發(fā)
titleClick:function(e){
this.setData({
//拿到當(dāng)前索引并動態(tài)改變
currentIndex:e.currentTarget.dataset.idx
第二步
上一步完成后,下級頁面再加一個滑動頁面,當(dāng)內(nèi)切換結(jié)束后,在做切換就是父級的切換操作
在內(nèi)容1的view中寫入代碼即可,由于父級代碼只能是小于2個頁面才有效,所以我們不用父級的這個滑動來做子滑動,不僅僅是因?yàn)閎ug的問題,這樣也避免了樣式和數(shù)據(jù)重復(fù)的問題
在這里我們插入wxml代碼:
view
scroll-viewscroll-x="true"scroll-left="{{scrollLeft}}"
viewclass="tab-item{{currentTab==0'active':''}}"data-current="0"bindtap="swichNav"熱門/view
viewclass="tab-item{{currentTab==1'active':''}}"data-current="1"bindtap="swichNav"影音/view
viewclass="tab-item{{currentTab==2'active':''}}"data-current="2"bindtap="swichNav"閱讀/view
viewclass="tab-item{{currentTab==3'active':''}}"data-current="3"bindtap="swichNav"游戲/view
viewclass="tab-item{{currentTab==4'active':''}}"data-current="4"bindtap="swichNav"福利/view
/scroll-view
swipercurrent="{{currentTab}}"duration="300"bindchange="switchTab"
swiper-item
scroll-viewscroll-y="true"
view
view
imagesrc="/9/B/A/0_qq_35230125"/image
/view
view
view剪影安卓版/view
view111人下載/view
view這只是一個簡介,看的話點(diǎn)擊詳情最大/view
/view
viewbindtap="show_hideModal"下載/view
!--navigatorurl="/pages/askExpert/expertDetail"問TA/navigator--
/view
/scroll-view
/swiper-item
swiper-item
scroll-viewscroll-y="true"
view
view
imagesrc="/avatar.png"/image
/view
view
view歡顏/view
view知名情感博主/view
view134個回答,2234人聽過/view
/view
navigatorurl="/pages/askExpert/expertDetail"問T2A/navigator
/view
/scroll-view
/swiper-item
swiper-item
scroll-viewscroll-y="true"
view
view
imagesrc="/avatar.png"/image
/view
view
view歡顏/view
view知名情感博主/view
view134個回答,2234人聽過/view
/view
navigatorurl="/pages/askExpert/expertDetail"問T2A/navigator
/view
/scroll-view
/swiper-item
swiper-item
scroll-viewscroll-y="true"
view
view
imagesrc="/avatar.png"/image
/view
view
view歡顏/view
view知名情感博主/view
view134個回答,2234人聽過/view
/view
navigatorurl="/pages/askExpert/expertDetail"問T2A/navigator
/view
/scroll-view
/swiper-item
swiper-item
scroll-viewscroll-y="true"
view
view
imagesrc="/avatar.png"/image
/view
view
view歡顏/view
view知名情感博主/view
view134個回答,2234人聽過/view
/view
navigatorurl="/pages/askExpert/expertDetail"問T2A/navigator
/view
/scroll-view
/swiper-item
/swiper
/view
js加入:
data:{
winHeight:"",//窗口高度
currentTab:0,//預(yù)設(shè)當(dāng)前項(xiàng)的值
scrollLeft:0,//tab標(biāo)題的滾動條位置
currentIndex:0,//默認(rèn)是活動項(xiàng)切換
hideModal:false//遮罩層
部分完整js代碼:
//pages/leftSlide/leftSlide.js
constApp=getApp()
Page({
data:{
winHeight:"",//窗口高度
currentTab:0,//預(yù)設(shè)當(dāng)前項(xiàng)的值
scrollLeft:0,//tab標(biāo)題的滾動條位置
currentIndex:0,//默認(rèn)是活動項(xiàng)切換
hideModal:false//遮罩層
//滾動切換標(biāo)簽樣式
switchTab:function(e){
letthat=this;
that.setData({
currentTab:e.detail.current
that.checkCor();
//點(diǎn)擊標(biāo)題切換當(dāng)前頁時(shí)改變樣式
swichNav:function(e){
varcur=e.target.dataset.current;
console.log(cur);
if(this.data.currentTaB==cur){returnfalse;}
else{
this.s
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 文明駕考試題及答案
- 物業(yè)人員考試題及答案
- 封窗美化改造方案
- 物理管理面試題及答案
- 模擬盲人考試題及答案
- 高端酒店客房樓頂花園使用權(quán)租賃合同
- 設(shè)計(jì)院新員工入職培訓(xùn)方案
- 教育功能概述
- 脊柱側(cè)彎的護(hù)理病例討論
- 感覺與挫折教育
- 交通運(yùn)輸行政執(zhí)法課件培訓(xùn)
- 中國肉類加工設(shè)備行業(yè)發(fā)展趨勢及發(fā)展前景研究報(bào)告2025-2028版
- 設(shè)備集中采購管理制度
- 高考數(shù)學(xué)專題-基本不等式求最值的常用方法(解析版)
- 中國上海市酒店行業(yè)市場調(diào)查研究及投資前景預(yù)測報(bào)告
- 2025春季學(xué)期國開電大本科《管理英語4》一平臺機(jī)考真題及答案(第四套)
- 2025上海紡織工業(yè)職工大學(xué)教師招聘考試試題
- DB13T 2770-2018 焊接熔深檢測方法
- 電力現(xiàn)貨市場基礎(chǔ)知識
- 網(wǎng)絡(luò)題庫財(cái)務(wù)會計(jì)知識競賽1000題(僅供自行學(xué)習(xí)使用)
- 員工轉(zhuǎn)崗培訓(xùn)管理制度
評論
0/150
提交評論