微信小程序?qū)崿F(xiàn)菜單左右聯(lián)動(dòng)
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)菜單左右聯(lián)動(dòng)的具體代碼,供大家參考,具體內(nèi)容如下
今天記錄一個(gè)個(gè)人寫(xiě)的二級(jí)聯(lián)動(dòng)示例。
下面是效果圖:
功能實(shí)現(xiàn)關(guān)鍵是使用控件scroll-view,下面直接上示例代碼。
頁(yè)面對(duì)應(yīng)的js文件:
Page({ data: { select_index:0, scroll_height:0, left: [{ id: 1, title: '選項(xiàng)一' }, { id: 2, title: '選項(xiàng)二' }, { id: 3, title: '選項(xiàng)三' }, { id: 4, title: '選項(xiàng)四' }, { id: 5, title: '選項(xiàng)五' }, { id: 6, title: '選項(xiàng)六' }, { id: 7, title: '選項(xiàng)七' } ], right:[ { id: 1, title: '選項(xiàng)一', content:[ { title:"產(chǎn)品一" }, { title: "產(chǎn)品二" }, { title: "產(chǎn)品三" }, { title: "產(chǎn)品四" }, ] }, { id: 2, title: '選項(xiàng)二', content: [ { title: "產(chǎn)品一" }, { title: "產(chǎn)品二" }, { title: "產(chǎn)品三" }, { title: "產(chǎn)品四" }, ] }, { id: 3, title: '選項(xiàng)三', content: [ { title: "產(chǎn)品一" }, { title: "產(chǎn)品二" }, { title: "產(chǎn)品三" }, { title: "產(chǎn)品四" }, ] }, { id: 4, title: '選項(xiàng)四', content: [ { title: "產(chǎn)品一" }, { title: "產(chǎn)品二" }, { title: "產(chǎn)品三" }, { title: "產(chǎn)品四" }, ] }, { id: 5, title: '選項(xiàng)五', content: [ { title: "產(chǎn)品一" }, { title: "產(chǎn)品二" }, { title: "產(chǎn)品三" }, { title: "產(chǎn)品四" }, ] }, { id: 6, title: '選項(xiàng)六', content: [ { title: "產(chǎn)品一" }, { title: "產(chǎn)品二" }, { title: "產(chǎn)品三" }, { title: "產(chǎn)品四" }, ] }, { id: 7, title: '選項(xiàng)七', content: [ { title: "產(chǎn)品一" }, { title: "產(chǎn)品二" }, { title: "產(chǎn)品三" }, { title: "產(chǎn)品四" }, ] } ] }, // 右邊scroll-view滑動(dòng)事件 scroll:function(e){ var h = e.detail.scrollTop var scroll_height = 0; var select_index; for (var i = 0; i < this.data.right.length; i++) { if (scroll_height >= h){ select_index = i; break; } scroll_height += this.data.right[i].content.length * 64 + 48; } this.setData({ select_index: i, }); }, //左邊點(diǎn)擊事件 left_tap:function(e){ var scroll_height = 0; for (var i = 0; i < e.target.dataset.index;i++){ scroll_height += this.data.right[i].content.length * 64 + 48; } console.log(scroll_height) this.setData({ scroll_height: scroll_height, select_index: e.target.dataset.index, }); } })
頁(yè)面對(duì)應(yīng)的wxml文件:
<view class='main'> <view class='left'> <scroll-view scroll-y="true" scroll-with-animation="true"> <block wx:for="{{left}}" wx:for-index="index"> <view class='{{select_index==index?"active":""}}' data-index="{{index}}" bindtap='left_tap'>{{item.title}}</view> </block> </scroll-view> </view> <view class='right'> <scroll-view scroll-y="true" scroll-top="{{scroll_height}}" bindscroll="scroll" scroll-with-animation="true"> <block wx:for="{{right}}"> <view class='block'> <view style='background: lightgrey;'>{{item.title}}</view> <view class='list'> <block wx:for="{{item.content}}"> <view>{{item.title}}</view> </block> </view> </view> </block> </scroll-view> </view> </view>
注:純個(gè)人編寫(xiě),用于記錄
為大家推薦現(xiàn)在關(guān)注度比較高的微信小程序教程一篇:《微信小程序開(kāi)發(fā)教程》小編為大家精心整理的,希望喜歡。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序?qū)崿F(xiàn)聯(lián)動(dòng)菜單
- 微信小程序scroll-view實(shí)現(xiàn)左右聯(lián)動(dòng)效果
- 微信小程序?qū)崿F(xiàn)左右聯(lián)動(dòng)
- 微信小程序scroll-view實(shí)現(xiàn)左右聯(lián)動(dòng)
- 微信小程序?qū)崿F(xiàn)購(gòu)物頁(yè)面左右聯(lián)動(dòng)
- 微信小程序?qū)崿F(xiàn)左右列表聯(lián)動(dòng)
- 微信小程序?qū)崿F(xiàn)左右聯(lián)動(dòng)的實(shí)戰(zhàn)記錄
- 微信小程序?qū)崿F(xiàn)菜單左右聯(lián)動(dòng)效果
相關(guān)文章
JavaScript處理數(shù)組數(shù)據(jù)的示例詳解
這篇文章主要為大家詳細(xì)介紹了JavaScript如何處理數(shù)組數(shù)據(jù),包括數(shù)據(jù)匹配和剔除,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起了解一下2023-10-10詳解springmvc 接收json對(duì)象的兩種方式
本篇文章主要介紹了springmvc 接收json對(duì)象的兩種方式,具有一定的參考價(jià)值,有需要的可以了解一下。2016-12-12CSS、JS文件無(wú)法正確加載至頁(yè)面問(wèn)題與解決辦法分享
這篇文章主要給大家介紹了關(guān)于CSS、JS文件無(wú)法正確加載至頁(yè)面問(wèn)題與解決辦法,文中通過(guò)圖文以及代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2024-01-01分享我對(duì)JS插件開(kāi)發(fā)的一些感想和心得
這篇文章主要給大家分享我對(duì)JS插件開(kāi)發(fā)的一些感想和心得的相關(guān)資料,需要的朋友可以參考下2016-02-02JS將滑動(dòng)門(mén)改為選項(xiàng)卡(需鼠標(biāo)點(diǎn)擊)的實(shí)現(xiàn)方法
這篇文章主要介紹了JS將滑動(dòng)門(mén)改為選項(xiàng)卡(需鼠標(biāo)點(diǎn)擊)的實(shí)現(xiàn)方法,涉及JavaScript頁(yè)面元素遍歷及樣式替換的相關(guān)技巧,再通過(guò)onmouseover與onclick即可分別實(shí)現(xiàn)滑動(dòng)門(mén)與選項(xiàng)卡兩種效果,需要的朋友可以參考下2015-09-09利用函數(shù)的惰性載入提高javascript代碼執(zhí)行效率
在 addEvent 函數(shù)每次調(diào)用的時(shí)候都要走一遍,如果瀏覽器支持其中的一種方法,那么他就會(huì)一直支持了,就沒(méi)有必要再進(jìn)行其他分支的檢測(cè)了2014-05-05JS賦值、淺拷貝和深拷貝(數(shù)組和對(duì)象的深淺拷貝)實(shí)例詳解
這篇文章主要介紹了JS賦值、淺拷貝和深拷貝,結(jié)合實(shí)例形式總結(jié)分析了JavaScript數(shù)組和對(duì)象的深淺拷貝相關(guān)概念、原理、操作技巧與使用注意事項(xiàng),需要的朋友可以參考下2020-03-03