超碰中文网,91久久精品日日躁夜夜躁欧美,一区二区三区精品道,一区二区国产在线观看,亚洲精品中文字幕乱码一区二区,天天看片高清影视在线观看,久久99精品久久久久蜜桃,久久成人影视

VPS參考測評推薦
專注分享VPS主機優惠信息
衡天云優惠活動
熱網互聯2026年促銷活動
hostkvm優惠促銷活動
zji優惠促銷活動
QQGNET優惠促銷活動
QQGNET優惠促銷活動

淺談如何通過小程序實現列表滾動的聯動效果

主機參考:VPS測評參考推薦/專注分享VPS服務器優惠信息!若您是商家可以在本站進行投稿,查看詳情!此外我們還提供軟文收錄、PayPal代付、廣告贊助等服務,查看詳情!
我們發布的部分優惠活動文章可能存在時效性,購買時建議在本站搜索商家名稱可查看相關文章充分了解該商家!若非中文頁面可使用Edge瀏覽器同步翻譯!PayPal代付/收錄合作

小程序是如何實現列表上下滾動的聯動效果的?下面這篇文章給大家介紹一下微信小程序開發列表上下滾動聯動效果的方法,希望對你有所幫助!

淺談如何通過小程序實現列表滾動的聯動效果

1.背景最近在做公司的一個小程序,其中一個設計是當列表上下滾動時,頂部的標簽欄與之鏈接,點擊標簽欄時,列表數據與之鏈接。

以下是實現的呈現:

1.gif

頂部標題區域不隨列表滾動;頭部以下的區域屬于滾動區。

2.實施原則介紹2.1。這個地方的實現主要依靠微信小程序原生的scroll-view組件。

使用其scroll-into-view屬性,可以單擊頂部的選項卡欄將頁面滾動到指定的列表位置;

使用bindscroll事件知道當前頁面的滾動距離,根據滾動距離切換標簽欄;

2.1頁面布局代碼先說界面的整體布局,主要分為兩部分,頭部固定區+可滾動列表區。

可滾動列表區的標題欄滾動一定距離后也要固定在頂部。

代碼實現:

lt!--index.wxml--> ltview class = 列表 gt lt!--頂部固定區域-->: lt;視圖樣式= 身高:88rpx寬度:100%;background -color:burlywood;text-align:居中; gt頭部區域: ltscroll -view scroll -y = ;true style = 寬度:100%;高度:{ { scrollAreaHeight } } px bindscroll = 滾動 scroll -into -view = ;{ { scrollToItem } } scroll -with -animation = ;true scroll -top = ;{ { scrollTop } } gt lt!--水平滾動標簽欄-->: lt;scroll -view scroll -x = ;true style = 身高:88rpx寬度:100%; gt ltview class = head-area {{float?'head -float # 39;: ''} } gt ltview class = head -area -item { { curSelectTab = = = index?'head -area -item -select # 39;: ''} } wx:for = ;{ { appGroupList } } bindtap = tabClick data -index = ;{ { index } } gt{ { item.name } } lt/view gt; lt/view gt; lt/scroll -view gt; lt!--數據列表-->: lt;view class = list -group ;style = 高度:{ { listGroupHeight } } px gt ltview class = 列表-組-項目 id = v _ { { index } } wx:for = ;{ { appGroupList } } data -index = ;{ { index } } gt ltview class = group -name ; gt{ { item.name } } lt/view gt; ltview class = 第三組+兒童 gt lt查看wx:for = ;{ { item.children } } class = 第3組+兒童-項目 style = 寬度:{ { itemWidth } } px gt ltimage src = { { item.url } } gt lt/image gt; lt視圖 gt{ { item.name } } lt/view gt; lt/view gt; lt/view gt; lt/view gt; lt/view gt; lt/scroll -view gt; lt/view gt;布局代碼中有幾點需要注意:

1.滾動區的高度計算。---通過獲取當前設備的窗口高度減去頂部固定區域的高度。

2.水平選項卡欄是否在頂部。---根據頁面的滾動距離,如果滾動距離大于等于水平標簽欄的高度,則設置頂部;

3.設置數據列表的ID = " v _ { { index } } ;Id,然后單擊選項卡欄滾動到指定位置就是基于這個id。

2.2樣式代碼/* * index.wxss * */。列表{寬度:100%;身高:100%;顯示器:flexflex -方向:列;} . head -area { display:flex;flex -方向:rowflex -wrap:nowrap;身高:88rpx寬度:100%;填充:0 10;} . head -area -item { display:flex;身高:88rpxtext-align:居中;寬度:150rpxalign -項:居中;justify -內容:居中;} . head -area -item -select { color:# 09bb 07;}圖像{ width:88 rpx;身高:88rpx} . list -group { display:flex;寬度:100%;身高:1000%;flex -方向:列;} . list -group -item { display:flex;寬度:100%;background -color:# AAA;flex -方向:列;} . group -name { height:88 rpx;顯示器:flextext-align:居中;align -項:居中;margin -left:20 rpx;} . group -子代{ display:flex;flex -方向:rowflex -wrap:wrap;寬度:100%;} . group -children -item { height:160 rpx;顯示器:flexflex -方向:列;justify -內容:居中;align -項:居中;}.head-float{位置:固定;頂配:88rpxbackground -color:# ffffff;}2.3邏輯代碼//index.jspage ({heightarr: [],//記錄高度距離:0,數據:{ appgroup list:[{ name:" Grouping 01 ;,孩子:[{ ;名稱 : 0 gt;測試, url : /images/bluetooth . png ;},{ 名稱 : 1 測試, url : /images/bluetooth . png ;},{ 名稱 : 2 , url : /images/bluetooth . png ;},{ 名稱 : 測試3 , url : /images/bluetooth . png ;},{ 名稱 : 測試4 , url : /images/bluetooth . png ;},{ 名稱 : 測試5 , url : /images/bluetooth . png ;},{ 名稱 : 測試6 , url : /images/bluetooth . png ;},{ 名稱 : 測試7 , url : /images/bluetooth . png ;}]},{ name: ;分組02,孩子:[{ ;名稱 : 0 gt;測試, url : /images/bluetooth . png ;},{ 名稱 : 1 測試, url : /images/bluetooth . png ;},{ 名稱 : 2 , url : /images/bluetooth . png ;},{ 名稱 : 測試3 , url : /images/bluetooth . png ;},{ 名稱 : 測試4 , url : /images/bluetooth . png ;},{ 名稱 : 測試5 , url : /images/bluetooth . png ;},{ 名稱 : 測試6 , url : /images/bluetooth . png ;},{ 名稱 : 測試7 , url : /images/bluetooth . png ;}]},{ name: ;分組03 ,孩子:[{ ;名稱 : 0 gt;測試, url : /images/bluetooth . png ;},{ 名稱 : 1 測試, url : /images/bluetooth . png ;},{ 名稱 : 2 , url : /images/bluetooth . png ;},{ 名稱 : 測試3 , url : /images/bluetooth . png ;},{ 名稱 : 測試4 , url : /images/bluetooth . png ;},{ 名稱 : 測試5 , url : /images/bluetooth . png ;},{ 名稱 : 測試6 , url : /images/bluetooth . png ;},{ 名稱 : 測試7 , url : /images/bluetooth . png ;}]},{ name: ;分組04 ,孩子:[{ ;名稱 : 0 gt;測試, url : /images/bluetooth . png ;},{ 名稱 : 1 測試, url : /images/bluetooth . png ;},{ 名稱 : 2 , url : /images/bluetooth . png ;},{ 名稱 : 測試3 , url : /images/bluetooth . png ;},{ 名稱 : 測試4 , url : /images/bluetooth . png ;},{ 名稱 : 測試5 , url : /images/bluetooth . png ;},{ 名稱 : 測試6 , url : /images/bluetooth . png ;},{ 名稱 : 測試7 , url : /images/bluetooth . png ;}]},{ name: ;分組05,孩子:[{ ;名稱 : 0 gt;測試, url : /images/bluetooth . png ;},{ 名稱 : 1 測試, url : /images/bluetooth . png ;},{ 名稱 : 2 , url : /images/bluetooth . png ;},{ 名稱 : 測試3 , url : /images/bluetooth . png ;},{ 名稱 : 測試4 , url : /images/bluetooth . png ;},{ 名稱 : 測試5 , url : /images/bluetooth . png ;},{ 名稱 : 測試6 , url : /images/bluetooth . png ;},{ 名稱 : 測試7 , url : /images/bluetooth . png ;}]},],itemWidth: wx.getSystemInfoSync()。windowWidth / 4,scrollarreaheight:wx . getsysteminfosync()。windowHeight - 44,float:false,Selecttab: 0,scrollToItem: null,scrollTop: 0,//到頂部列表的距離GroupHeight: 0,},on ready:function(){ this . cacluitemheight();},scroll:function(e){ console . log( ;卷軸: ,e);if(e . detail . scroll top gt;= 44){ this . setdata({ float:true })} else if(e . detail . scroll top lt;44){ this . setdata({ float:false })} let scroll top = e . detail . scroll top;let current = this . data . curselecttab;if(scroll top gt;= this.distance) {// Page向上滑動//如果列表的當前可視區域從底部到頂部的距離超過了所選項目從當前列表頂部的高度(且沒有下標越界),則選項卡欄If(current+1 := 0 ; scrollTop ltthis . height arr[current -1]){ this . setdata({ curselecttab:current -1 } } }//更新到頂部的距離this.distance = scrollTop},tab click(e){ this . setdata({ curSelectTab:e . current target . dataset . index,scrollToItem: ;v _ +e .當前目標。數據集。index})},//計算每一項的高度,cacluItemHeight(){ let that = this;this . height arr =[];設h = 0;const query = wx . createselectquery();query . select all( # 39;. list -group -item # 39;).bounding client rect()query . exec(function(RES){ RES[0]。forEach((item)= gt;{ h+= item . height;that . heightarr . push(h);})console . log(that . heightarr);that . setdata({ listgroupheheight:that . heightarr[that . heightarr . length -1]} } })主要用在兩個地方的邏輯代碼中:

1.cacluItemHeight計算列表中項的高度數組,并將最終計算結果保存在heightArr數組中。

ARR數組中每一項的值都是在前一項的基礎上累加的。

2.在scroll中判斷當前滾動方向,根據滾動判斷當前方向,然后根據滾動距離設置當前選擇的選項卡。

好了,就這些。基于以上內容,基本可以達到想要的滾動聯動和tab聯動效果。

【相關學習推薦:小程序開發教程】以上是小程序如何實現列表上下滾動聯動效果的詳細內容。請多關注主機參考其他相關文章!

這幾篇文章你可能也喜歡:

本文由主機參考刊發,轉載請注明:淺談如何通過小程序實現列表滾動的聯動效果 http://m.k2270.com/75384.html

【騰訊云】領8888元采購禮包,搶爆款云服務器 每月 9元起,個人開發者加享折上折!
打賞
轉載請注明原文鏈接:主機參考 » 淺談如何通過小程序實現列表滾動的聯動效果
主機參考僅做資料收集,不對商家任何信息及交易做信用擔保,購買前請注意風險,有交易糾紛請自行解決!請查閱:特別聲明

評論 搶沙發

評論前必須登錄!