<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
首先通過swiper建立一個簡單的多tab頁面
通過觸發pagechange1方法中的事件對currentIndex來進行賦值,又通過currentIndex的改變使前端wxml對應更改,這個部分對滑動和點選的操作都一樣,無非就是使currentIndex對應到各自的位置,通過數位來決定位置
//滑動 pagechange1: function (ee) { if ("touch" === ee.detail.source) { let currentPageIndex = this.data.currentIndex; currentPageIndex = (currentPageIndex + 1) % 2; this.setData({ currentIndex: currentPageIndex, }) } },
//點選tab時觸發 titleClick: function (e) { this.setData({ //拿到當前索引並動態改變 currentIndex: e.currentTarget.dataset.idx }) },
這個部分完整程式碼如下:
wxml
<view> <!-- Tab佈局 --> <view class='navBox'> <view class='titleBox' bindtap='titleClick' data-idx='0'> <text class="{{0 == currentIndex ? 'fontColorBox' : ''}}">安卓</text> <hr class="{{0 == currentIndex ? 'lineBox' : 'notLineBox'}}" /> </view> <view class='titleBox' bindtap='titleClick' data-idx='1'> <text class="{{1 == currentIndex ? 'fontColorBox1' : ''}}">蘋果</text> <hr class="{{1 == currentIndex ? 'lineBox' : 'notLineBox'}} " /> </view> </view> <!-- 內容佈局 --> <swiper class='swiperTtemBox' bindchange='pagechange1' current='{{currentIndex}}'> <swiper-item class='swiperTtemBox'> <view>內容1</view> </swiper-item> <swiper-item class='swiperTtemBox'> <view>內容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; } .navBox view: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 { /* 底部內容樣式 */ height: 100vh; overflow: scroll; margin: 12rpx 0rpx; background: white; font-size: 28rpx; }
js
const app = getApp() Page({ data: { currentIndex: 0, //預設第一個 }, pagechange1: function (ee) { if ("touch" === ee.detail.source) { let currentPageIndex = this.data.currentIndex; currentPageIndex = (currentPageIndex + 1) % 2; this.setData({ currentIndex: currentPageIndex, }) } }, //點選tab時觸發 titleClick: function (e) { this.setData({ //拿到當前索引並動態改變 currentIndex: e.currentTarget.dataset.idx }) }, })
上一步完成後,下級頁面再加一個滑動頁面,當內切換結束後,在做切換就是父級的切換操作
在“內容1”的view中 寫入程式碼即可,由於父級程式碼只能是小於2個頁面才有效,所以我們不用父級的這個滑動來做子滑動,不僅僅是因為bug的問題,這樣也避免了樣式和資料重複的問題
在這裡我們插入wxml程式碼:
<view > <scroll-view scroll-x="true" class="tab-h" scroll-left="{{scrollLeft}}"> <view class="tab-item {{currentTab==0?'active':''}}" data-current="0" bindtap="swichNav">熱門</view> <view class="tab-item {{currentTab==1?'active':''}}" data-current="1" bindtap="swichNav">影音</view> <view class="tab-item {{currentTab==2?'active':''}}" data-current="2" bindtap="swichNav">閱讀</view> <view class="tab-item {{currentTab==3?'active':''}}" data-current="3" bindtap="swichNav">遊戲</view> <view class="tab-item {{currentTab==4?'active':''}}" data-current="4" bindtap="swichNav">福利</view> </scroll-view> <swiper class="tab-content" current="{{currentTab}}" duration="300" bindchange="switchTab" style="height:{{winHeight}}rpx"> <swiper-item> <scroll-view scroll-y="true" class="scoll-h" > <view class="item-ans"> <view class="avatar"> <image class="img" src="https://profile.csdnimg.cn/9/B/A/0_qq_35230125"></image> </view> <view class="expertInfo"> <view class="name">剪影安卓版</view> <view class="tag">111人下載</view> <view>這只是一個簡介,看的話點選詳情最大</view> </view> <view class="askBtn" bindtap="show_hideModal">下載</view> <!-- <navigator url="/pages/askExpert/expertDetail" class="askBtn">問TA</navigator> --> </view> </scroll-view> </swiper-item> <swiper-item> <scroll-view scroll-y="true" class="scoll-h" > <view class="item-ans"> <view class="avatar"> <image class="img" src="http://ookzqad11.bkt.clouddn.com/avatar.png"></image> </view> <view class="expertInfo"> <view class="name">歡顏</view> <view class="tag">知名情感博主</view> <view class="answerHistory">134個回答,2234人聽過 </view> </view> <navigator url="/pages/askExpert/expertDetail" class="askBtn">問T2A</navigator> </view> </scroll-view> </swiper-item> <swiper-item> <scroll-view scroll-y="true" class="scoll-h" > <view class="item-ans"> <view class="avatar"> <image class="img" src="http://ookzqad11.bkt.clouddn.com/avatar.png"></image> </view> <view class="expertInfo"> <view class="name">歡顏</view> <view class="tag">知名情感博主</view> <view class="answerHistory">134個回答,2234人聽過 </view> </view> <navigator url="/pages/askExpert/expertDetail" class="askBtn">問T2A</navigator> </view> </scroll-view> </swiper-item> <swiper-item> <scroll-view scroll-y="true" class="scoll-h" > <view class="item-ans"> <view class="avatar"> <image class="img" src="http://ookzqad11.bkt.clouddn.com/avatar.png"></image> </view> <view class="expertInfo"> <view class="name">歡顏</view> <view class="tag">知名情感博主</view> <view class="answerHistory">134個回答,2234人聽過 </view> </view> <navigator url="/pages/askExpert/expertDetail" class="askBtn">問T2A</navigator> </view> </scroll-view> </swiper-item> <swiper-item> <scroll-view scroll-y="true" class="scoll-h" > <view class="item-ans"> <view class="avatar"> <image class="img" src="http://ookzqad11.bkt.clouddn.com/avatar.png"></image> </view> <view class="expertInfo"> <view class="name">歡顏</view> <view class="tag">知名情感博主</view> <view class="answerHistory">134個回答,2234人聽過 </view> </view> <navigator url="/pages/askExpert/expertDetail" class="askBtn">問T2A</navigator> </view> </scroll-view> </swiper-item> </swiper> </view>
js加入:
data: { winHeight:"",//視窗高度 currentTab:0, //預設當前項的值 scrollLeft:0, //tab標題的卷軸位置 currentIndex: 0, //預設是活動項 切換 hideModal:false//遮罩層 },
部分完整js程式碼:
// pages/leftSlide/leftSlide.js const App = getApp() Page({ data: { winHeight:"",//視窗高度 currentTab:0, //預設當前項的值 scrollLeft:0, //tab標題的卷軸位置 currentIndex: 0, //預設是活動項 切換 hideModal:false//遮罩層 }, // 捲動切換標籤樣式 switchTab:function(e){ let that=this; that.setData({ currentTab:e.detail.current }); that.checkCor(); }, // 點選標題切換當前頁時改變樣式 swichNav:function(e){ var cur=e.target.dataset.current; console.log(cur); if(this.data.currentTaB==cur){return false;} else{ this.setData({ currentTab:cur }) } }, //判斷當前捲動超過一屏時,設定tab標題卷軸。 checkCor:function(){ if (this.data.currentTab>4){ this.setData({ scrollLeft:300 }) }else{ this.setData({ scrollLeft:0 }) } }, pagechange: function (ee) { let that=this; console.log(ee.detail.source) if ("touch" === ee.detail.source) { let currentPageIndex = that.data.currentIndex; currentPageIndex = (currentPageIndex+1) % 2; that.setData({ currentIndex: currentPageIndex, }) } }, // 彈出、隱藏遮罩層 show_hideModal:function(){ let that=this; that.setData({ hideModal:true }) }, hideModal:function(){ let that=this; that.setData({ hideModal:false }) }, // // 切換 // 切換swiper-item觸發bindchange事件 pagechange: function (e) { // 通過touch判斷,改變tab的下標值 if ("touch" === e.detail.source) { let currentPageIndex = this.data.currentIndex; currentPageIndex = (currentPageIndex + 1) % 2; // 拿到當前索引並動態改變 this.setData({ currentIndex: currentPageIndex, }) } }, //點選tab時觸發 titleClick: function (e) { this.setData({ //拿到當前索引並動態改變 currentIndex: e.currentTarget.dataset.idx }) }, onLoad: function (options) { // 頁面初始化 options為頁面跳轉所帶來的引數 var that = this; // 高度自適應 wx.getSystemInfo( { success: function( res ) { var clientHeight=res.windowHeight, clientWidth=res.windowWidth, rpxR=750/clientWidth; var calc=clientHeight*rpxR-180; console.log(calc) that.setData( { winHeight: calc }); } }); }, onReady: function () { // 頁面渲染完成 }, onShow: function () { // 頁面顯示 }, onHide: function () { // 頁面隱藏 }, onUnload: function () { // 頁面關閉 } })
樣式修改為下方的即可
/* 頁面切換 */ Page { /* 全域性樣式 */ background: rgb(244, 245, 249); height: 100%; position: fixed; } .fontColorBox, .fontColorBox1 { /* 文字預設顏色 */ color: black; } .navBox { /* 頂部tab盒子樣式 */ width: 100%; height: 80rpx; background: white; flex-direction: row; display: flex; align-items: center; justify-content: center; } /* 最後一個tab標題的樣式 */ /* .navBox view:last-child { padding-left: 20%; } */ .titleBox { width: 100rpx; /* 未選中文字的樣式 */ 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 { /* 底部內容樣式 */ height: 100vh; overflow: scroll; margin: 12rpx 0rpx; background: white; font-size: 28rpx; } /* 頁面切換 */ /* 遮罩層 */ /* pages/index/components/buy/index.wxss */ .flex { display: flex; align-items: center; } .box { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 1000; width: 100vw; height: 100vh; background: rgba(0, 0, 0, 0.5); display: flex; flex-direction: column; } .empty-box { flex: 1; background-color: transparent; } /* 內容檢視 */ .content { width: 100vw; background: rgba(255, 255, 255, 1); opacity: 1; border-radius: 20px 20px 0px 0px; z-index: 1001; } /* modal按鈕 */ .button { width: 100vw; padding: 4rpx 20rpx 10rpx 40rpx; } .button >view { width: calc(100% - 80rpx); height: 98rpx; border-radius: 50rpx; line-height: 98rpx; text-align: center; font-size: 32rpx; font-family: PingFang SC; font-weight: bold; color: rgba(255, 255, 255, 1); background: yellowgreen; opacity: 1; } /* 內部切換欄 */ .tab-h{ height: 80rpx;width: 100%; box-sizing: border-box;overflow: hidden;line-height: 80rpx;background: #F7F7F7; font-size: 16px; white-space: nowrap;position: fixed;top: 0; left: 0; z-index: 99;} .tab-item{margin:0 36rpx;display: inline-block;} .tab-item.active{color: #4675F9;position: relative;} .tab-item.active:after{ content: "";display: block;height: 8rpx;width: 52rpx;background: #4675F9;position: absolute; bottom: 0;left: 5rpx;border-radius: 16rpx;} .item-ans{ width: 100%;display: flex; flex-grow: row no-wrap;justify-content: space-between; padding: 30rpx;box-sizing: border-box; height: 180rpx;align-items: center;border-bottom: 1px solid #F2F2F2;} .avatar{width: 100rpx;height: 100rpx;position: relative;padding-right: 30rpx;} .avatar .img{width: 100%;height: 100%;} .avatar .doyen{width: 40rpx;height: 40rpx;position: absolute;bottom: -2px;right: 20rpx;} .expertInfo{font-size: 12px;flex-grow: 2;color: #B0B0B0;line-height: 1.5em;} .expertInfo .name{font-size: 16px;color:#000;margin-bottom: 6px;} .askBtn{ width: 120rpx;height: 60rpx;line-height: 60rpx;text-align: center;font-size: 14px; border-radius: 60rpx;border: 1px solid #4675F9; color:#4675F9;} .tab-content{margin-top: 80rpx;} .scoll-h{height: 100%;}
最後完整的程式碼如下:
<!-- 切換 --> <view> <!-- Tab佈局 --> <view class='navBox'> <view class='titleBox' bindtap='titleClick' data-idx='0' style="width: 200rpx;"> <text class="{{0 == currentIndex ? 'fontColorBox' : ''}}">安卓</text> <hr class="{{0 == currentIndex ? 'lineBox' : 'notLineBox'}}" /> </view> <view class='titleBox' bindtap='titleClick' data-idx='1' style="width: 200rpx;"> <text class="{{1 == currentIndex ? 'fontColorBox1' : ''}}">蘋果</text> <hr class="{{1 == currentIndex ? 'lineBox' : 'notLineBox'}} " /> </view> </view> <!-- 內容佈局 --> <swiper class='swiperTtemBox' bindchange='pagechange' current='{{currentIndex}}'> <swiper-item class='swiperTtemBox'> <!-- 安卓 --> <view > <scroll-view scroll-x="true" class="tab-h" scroll-left="{{scrollLeft}}"> <view class="tab-item {{currentTab==0?'active':''}}" data-current="0" bindtap="swichNav">熱門</view> <view class="tab-item {{currentTab==1?'active':''}}" data-current="1" bindtap="swichNav">影音</view> <view class="tab-item {{currentTab==2?'active':''}}" data-current="2" bindtap="swichNav">閱讀</view> <view class="tab-item {{currentTab==3?'active':''}}" data-current="3" bindtap="swichNav">遊戲</view> <view class="tab-item {{currentTab==4?'active':''}}" data-current="4" bindtap="swichNav">福利</view> </scroll-view> <swiper class="tab-content" current="{{currentTab}}" duration="300" bindchange="switchTab" style="height:{{winHeight}}rpx"> <swiper-item> <scroll-view scroll-y="true" class="scoll-h" > <view class="item-ans"> <view class="avatar"> <image class="img" src="https://profile.csdnimg.cn/9/B/A/0_qq_35230125"></image> </view> <view class="expertInfo"> <view class="name">剪影安卓版</view> <view class="tag">111人下載</view> <view>這只是一個簡介,看的話點選詳情最大</view> </view> <view class="askBtn" bindtap="show_hideModal">下載</view> <!-- <navigator url="/pages/askExpert/expertDetail" class="askBtn">問TA</navigator> --> </view> </scroll-view> </swiper-item> <swiper-item> <scroll-view scroll-y="true" class="scoll-h" > <view class="item-ans"> <view class="avatar"> <image class="img" src="http://ookzqad11.bkt.clouddn.com/avatar.png"></image> </view> <view class="expertInfo"> <view class="name">歡顏</view> <view class="tag">知名情感博主</view> <view class="answerHistory">134個回答,2234人聽過 </view> </view> <navigator url="/pages/askExpert/expertDetail" class="askBtn">問T2A</navigator> </view> </scroll-view> </swiper-item> <swiper-item> <scroll-view scroll-y="true" class="scoll-h" > <view class="item-ans"> <view class="avatar"> <image class="img" src="http://ookzqad11.bkt.clouddn.com/avatar.png"></image> </view> <view class="expertInfo"> <view class="name">歡顏</view> <view class="tag">知名情感博主</view> <view class="answerHistory">134個回答,2234人聽過 </view> </view> <navigator url="/pages/askExpert/expertDetail" class="askBtn">問T2A</navigator> </view> </scroll-view> </swiper-item> <swiper-item> <scroll-view scroll-y="true" class="scoll-h" > <view class="item-ans"> <view class="avatar"> <image class="img" src="http://ookzqad11.bkt.clouddn.com/avatar.png"></image> </view> <view class="expertInfo"> <view class="name">歡顏</view> <view class="tag">知名情感博主</view> <view class="answerHistory">134個回答,2234人聽過 </view> </view> <navigator url="/pages/askExpert/expertDetail" class="askBtn">問T2A</navigator> </view> </scroll-view> </swiper-item> <swiper-item> <scroll-view scroll-y="true" class="scoll-h" > <view class="item-ans"> <view class="avatar"> <image class="img" src="http://ookzqad11.bkt.clouddn.com/avatar.png"></image> </view> <view class="expertInfo"> <view class="name">歡顏</view> <view class="tag">知名情感博主</view> <view class="answerHistory">134個回答,2234人聽過 </view> </view> <navigator url="/pages/askExpert/expertDetail" class="askBtn">問T2A</navigator> </view> </scroll-view> </swiper-item> </swiper> </view> <!-- 安卓 --> </swiper-item> <swiper-item class='swiperTtemBox'> <view>活動內容</view> </swiper-item> </swiper> </view> <!-- 切換 --> <!-- 彈窗 --> <!--pages/index/components/buy/index.wxml--> <view class="box" hidden="{{!hideModal}}"> <view class="empty-box" bindtap="hideModal" id="empty-box"></view> <scroll-view scroll-y style="max-height:80vh;"> <view class="content" style="transform:translateY({{translateY}}px);" animation="{{animate}}"> <!-- boll --> <view style="height: 750rpx;display: flex;flex-direction: column;align-items: center;"> <view style="height: 750rpx;width: 700rpx;display: flex;flex-direction: column;align-items: center;padding-top: 10rpx;"> <!-- 圖示icon --> <view style="width: 100rpx;height: 100rpx;border-radius: 10rpx;"> <image src="http://pic.2265.com/upload/2017-5/2017515111376293.png" style="width: 100rpx;height: 100rpx;"></image> </view> <view style="width: 730rpx;height: 500rpx;"> <text decode="{{true}}" style="width: 730rpx;height: 400rpx;">      ❤️❤️❤️❤️❤️❤️
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45