微信小程序如何實(shí)現(xiàn)菜單左右聯(lián)動(dòng)-創(chuàng)新互聯(lián)

小編這次要給大家分享的是微信小程序如何實(shí)現(xiàn)菜單左右聯(lián)動(dòng),文章內(nèi)容豐富,感興趣的小伙伴可以來了解一下,希望大家閱讀完這篇文章之后能夠有所收獲。

站在用戶的角度思考問題,與客戶深入溝通,找到北侖網(wǎng)站設(shè)計(jì)與北侖網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:做網(wǎng)站、網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、域名注冊(cè)、虛擬主機(jī)、企業(yè)郵箱。業(yè)務(wù)覆蓋北侖地區(qū)。

今天記錄一個(gè)個(gè)人寫的二級(jí)聯(lián)動(dòng)示例。

下面是效果圖:

微信小程序如何實(shí)現(xiàn)菜單左右聯(lián)動(dòng)

功能實(shí)現(xiàn)關(guān)鍵是使用控件scroll-view,下面直接上示例代碼。

頁面對(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,
 });
 }
})

文章標(biāo)題:微信小程序如何實(shí)現(xiàn)菜單左右聯(lián)動(dòng)-創(chuàng)新互聯(lián)
網(wǎng)頁鏈接:http://muchs.cn/article48/dppcep.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、用戶體驗(yàn)服務(wù)器托管、網(wǎng)站導(dǎo)航、靜態(tài)網(wǎng)站、自適應(yīng)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化