小程序?qū)崿F(xiàn)分頁(yè)效果
本文實(shí)例為大家分享了小程序?qū)崿F(xiàn)分頁(yè)效果展示的具體代碼,供大家參考,具體內(nèi)容如下
<view class="pages_box"> <view bindtap="pagesFn" class="{{pagesNum==0?'active':''}}" data-type="0">上一頁(yè)</view> <block wx:for="shujuDataArr11111" wx:key="index" wx:if="{{index+1<4}}"> <view wx:if="{{tyindex+index <=maxPages}}" bindtap="pagesFn" class="{{pagesNum==tyindex+index?'active':''}}" data-type="{{tyindex+index}}">{{tyindex+index}}</view> </block> <view bindtap="pagesFn" class="{{pagesNum==-1?'active':''}}" data-type="-1">下一頁(yè)</view> </view>
js:
// pages/ceshiPages/index.js Page({ /** * 頁(yè)面的初始數(shù)據(jù) */ data: { pagesNum:1, maxPages:15,//分頁(yè)總數(shù)量 tyindex:1 }, /** * 生命周期函數(shù)--監(jiān)聽頁(yè)面加載 */ onLoad: function (options) { }, pagesFn:function(e){ let type = e.currentTarget.dataset.type; let _that = this; if(typeof type == "string"){//上下頁(yè) if(type == "previous_page"){//上一頁(yè) if(_that.data.pagesNum-1 >0){ _that.setData({ pagesNum:_that.data.pagesNum-1, tyindex:_that.data.pagesNum-1, }) } console.log(_that.data.pagesNum) }else{//下一頁(yè) if(_that.data.pagesNum+1 <= _that.data.maxPages){ if((_that.data.pagesNum+1)%3 == 0){ _that.setData({ tyindex:_that.data.pagesNum+1, }) } _that.setData({ pagesNum:_that.data.pagesNum+1, }) console.log(_that.data.pagesNum) } } }else{ console.log(_that.data.pagesNum) if(type>_that.data.pagesNum){ if(type <= _that.data.maxPages){ _that.setData({ tyindex:type, pagesNum:type, }) } } if(type<_that.data.pagesNum){ if(type >=1){ _that.setData({ tyindex:type, pagesNum:type, }) } } console.log(_that.data.pagesNum) } }, /** * 生命周期函數(shù)--監(jiān)聽頁(yè)面初次渲染完成 */ onReady: function () { }, /** * 生命周期函數(shù)--監(jiān)聽頁(yè)面顯示 */ onShow: function () { }, /** * 生命周期函數(shù)--監(jiān)聽頁(yè)面隱藏 */ onHide: function () { }, /** * 生命周期函數(shù)--監(jiān)聽頁(yè)面卸載 */ onUnload: function () { }, /** * 頁(yè)面相關(guān)事件處理函數(shù)--監(jiān)聽用戶下拉動(dòng)作 */ onPullDownRefresh: function () { }, /** * 頁(yè)面上拉觸底事件的處理函數(shù) */ onReachBottom: function () { }, /** * 用戶點(diǎn)擊右上角分享 */ onShareAppMessage: function () { } })
CSS:
/* pages/ceshiPages/index.wxss */ .pages_box{ margin-top: 20rpx; display: flex; display: -webkit-flex; flex-direction: row; justify-content: space-around; align-content: flex-start; flex-wrap: nowrap; } .pages_box>view{ line-height: 60rpx; font-size: 30rpx; border: 1px solid #A0A0A0; background-color: #F7F7F7; display: inline-block; padding: 0 25rpx; margin-left: 12rpx; color: #64646C; border-radius: 10rpx; } .pages_box>view.active{ background-color: #FCD821; border-color: #F39800; } .pages_box>view:last-child,.pages_box>view:first-child{ border-radius: 60rpx; padding: 0 30rpx; }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序?qū)崿F(xiàn)列表分頁(yè)功能
- 微信小程序?qū)崿F(xiàn)分頁(yè)查詢?cè)斀?/a>
- 微信小程序?qū)崿F(xiàn)分頁(yè)加載效果
- 微信小程序之搜索分頁(yè)功能的實(shí)現(xiàn)代碼
- 小程序分頁(yè)實(shí)踐之編寫可復(fù)用分頁(yè)組件
- 微信小程序云開發(fā)實(shí)現(xiàn)數(shù)據(jù)添加、查詢和分頁(yè)
- 微信小程序分頁(yè)加載的實(shí)例代碼
- 微信小程序?qū)崙?zhàn)之上拉(分頁(yè)加載)效果(2)
- 微信小程序模板之分頁(yè)滑動(dòng)欄
- 小程序?qū)崿F(xiàn)簡(jiǎn)單分頁(yè)組件
相關(guān)文章
JS 中document.write()的用法和清空的原因淺析
這篇文章主要介紹了JS 中document.write()的用法和清空的原因淺析,需要的朋友可以參考下2017-12-12Immutable 在 JavaScript 中的應(yīng)用
在 JavaScript 中,對(duì)象是引用類型的數(shù)據(jù),其優(yōu)點(diǎn)在于頻繁的修改對(duì)象時(shí)都是在原對(duì)象的基礎(chǔ)上修改,并不需要重新創(chuàng)建,這樣可以有效的利用內(nèi)存,不會(huì)造成內(nèi)存空間的浪費(fèi),對(duì)象的這種特性可以稱之為 Mutable,中文的字面意思是「可變」2016-05-05JS 插件dropload下拉刷新、上拉加載使用小結(jié)
這篇文章主要介紹了JS 插件dropload下拉刷新、上拉加載使用小結(jié),需要的朋友可以參考下2017-04-04JavaScript兼容性總結(jié)之獲取非行間樣式案例
這篇文章主要介紹了JavaScript兼容性總結(jié)之獲取非行間樣式的相關(guān)資料,需要的朋友可以參考下2016-08-08前端React?Nextjs中的TS類型過濾實(shí)用技巧
今天就來介紹一個(gè)在其它開源庫(kù)中見到的既花里胡哨,又實(shí)用的TS類型——TS類型過濾,你會(huì)發(fā)現(xiàn)這些?TS騷操作真的很重要,因?yàn)樗芎芎玫貛椭阕鲮o態(tài)類型校驗(yàn)2022-04-04解決bootstrap中下拉菜單點(diǎn)擊后不關(guān)閉的問題
今天小編就為大家分享一篇解決bootstrap中下拉菜單點(diǎn)擊后不關(guān)閉的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-08-08JavaScript點(diǎn)擊按鈕后彈出透明浮動(dòng)層的方法
這篇文章主要介紹了JavaScript點(diǎn)擊按鈕后彈出透明浮動(dòng)層的方法,可實(shí)現(xiàn)點(diǎn)擊按鈕彈出居中的透明浮動(dòng)層的效果,涉及javascript操作鼠標(biāo)事件及頁(yè)面樣式的相關(guān)技巧,需要的朋友可以參考下2015-05-05