




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
第小程序?qū)崿F(xiàn)頁面多級來回切換的示例代碼目錄第一步第二步全部完整代碼wxmljscss
第一步
首先通過swiper創(chuàng)建一個簡單的多tab頁面
通過觸發(fā)pagechange1方法中的事件對currentIndex來進行賦值,又通過currentIndex的改變使前端wxml對應(yīng)更改,這個部分對滑動和點擊的操作都一樣,無非就是使currentIndex對應(yīng)到各自的位置,通過數(shù)字來決定位置
//滑動
pagechange1:function(ee){
if("touch"===ee.detail.source){
letcurrentPageIndex=this.data.currentIndex;
currentPageIndex=(currentPageIndex+1)%2;
this.setData({
currentIndex:currentPageIndex,
//點擊tab時觸發(fā)
titleClick:function(e){
this.setData({
//拿到當前索引并動態(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{
/*文字默認顏色*/
color:black;
.navBox{
/*頂部tab盒子樣式*/
width:100%;
height:108rpx;
background:white;
display:flex;
align-items:center;
justify-content:center;
.navBoxview:last-child{
/*最后一個tab標題的樣式*/
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,//默認第一個
pagechange1:function(ee){
if("touch"===ee.detail.source){
letcurrentPageIndex=this.data.currentIndex;
currentPageIndex=(currentPageIndex+1)%2;
this.setData({
currentIndex:currentPageIndex,
//點擊tab時觸發(fā)
titleClick:function(e){
this.setData({
//拿到當前索引并動態(tài)改變
currentIndex:e.currentTarget.dataset.idx
第二步
上一步完成后,下級頁面再加一個滑動頁面,當內(nèi)切換結(jié)束后,在做切換就是父級的切換操作
在內(nèi)容1的view中寫入代碼即可,由于父級代碼只能是小于2個頁面才有效,所以我們不用父級的這個滑動來做子滑動,不僅僅是因為bug的問題,這樣也避免了樣式和數(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這只是一個簡介,看的話點擊詳情最大/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è)當前項的值
scrollLeft:0,//tab標題的滾動條位置
currentIndex:0,//默認是活動項切換
hideModal:false//遮罩層
部分完整js代碼:
//pages/leftSlide/leftSlide.js
constApp=getApp()
Page({
data:{
winHeight:"",//窗口高度
currentTab:0,//預(yù)設(shè)當前項的值
scrollLeft:0,//tab標題的滾動條位置
currentIndex:0,//默認是活動項切換
hideModal:false//遮罩層
//滾動切換標簽樣式
switchTab:function(e){
letthat=this;
that.setData({
currentTab:e.detail.current
that.checkCor();
//點擊標題切換當前頁時改變樣式
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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年抗肝片吸蟲病藥項目資金申請報告代可行性研究報告
- 浙江省錢塘聯(lián)盟2024-2025學(xué)年高一下學(xué)期4月期中聯(lián)考試題 地理 PDF版含答案
- 醫(yī)療實驗室標準化管理的關(guān)鍵要素
- 線粒體腦肌病的臨床護理
- 三通訂貨合同范例
- 從全球化到數(shù)字化探索未來商業(yè)的基石-區(qū)塊鏈技術(shù)
- 個人競業(yè)合同范例
- 小兒原發(fā)性腦干損傷的臨床護理
- mv拍攝合同范例
- 伊犁勞動合同范例
- 2024年浙江省仙居縣事業(yè)單位公開招聘教師崗筆試題帶答案
- 2025年地理高考復(fù)習 專題05“演變過程類”選擇題答題技巧(解析版)
- 軟切片安全挑戰(zhàn)-全面剖析
- 生活垃圾合同終止協(xié)議
- 運動康復(fù)與體能訓(xùn)練理療中心商業(yè)計劃書
- 山東能源電力集團招聘筆試題庫2025
- GB/T 3091-2025低壓流體輸送用焊接鋼管
- 醫(yī)療技術(shù)品牌的創(chuàng)新與傳播策略
- 湖北省武漢市2025屆高中畢業(yè)生四月調(diào)研考試生物試題及答案(武漢四調(diào))
- 陪護公司管理制度規(guī)范
- 2024年天津卷高考語文真題含解析
評論
0/150
提交評論