日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

vue中实现美团双级联动菜单

發布時間:2023/12/15 vue 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue中实现美团双级联动菜单 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

利用better-Scroll插件來實現移動端滾動效果記得先安裝再引入

<div class="core-container" ><div class="wrapper" style="height:500px;overflow:hidden"><div class="scroll-content"><div class="scroll-item" v-for="(item, index) in listsd" :key="index" @click="clickHandler(index)" style="fontSize:80px":style="{color:index === currentIndex ? 'red':''}">{{item}}</div></div></div></div><div class="core-container"><div class="scroll-wrapper" ref="scroll" style="height:600px;overflow:hidden"><div class="scroll-content" ref="list"><div class="scroll-item" v-for="(item, index) in emojis" :key="index">{{item}}</div></div></div></div> import BScroll from 'better-scroll' data(){return{listsd:['1','2','3','4','5'],scrollY:0,tops: [],emojis: ['😀 😁 😂 🤣 😃','😄 😅 😆 😉 😊','😫 😴 😌 😛 😜','👆🏻 😒 😓 😔 👇🏻','😑 😶 🙄 😏 😣','😞 😟 😤 😢 😭','🤑 😲 🙄 🙁 😖','👍 👎 👊 ? 🤛',],scrollY:0, //滑動的時候的值tops: [], //存放盒子高度的數組} }, mounted() {this.init() //初始化betterscroll插件this.initTops() },computed:{currentIndex(){ //這里的currenIndex是為了實現右邊滑動到哪里,左邊那個選項高亮const {scrollY,tops} = thisconst index = tops.findIndex((top,index) =>{return scrollY >= top && scrollY<tops[index + 1]//滑動的時候數值大于等于tops數組第一個小于tops數組第二個,就讓第一個選項高亮,大于等于數組第二個小于數組第三個就讓第二個選項高亮})console.log(index)return index}},methods: {init() {this.bs = new BScroll('.scroll-wrapper', {probeType: 3,click: true})const foodsScroll = new BScroll('.wrapper', {probeType: 3,click: true})this.bs.on('scroll',({x,y}) =>{this.scrollY = Math.abs(y) //把獲取到的y值賦給scrollY// console.log(this.scrollY)})// this.bs.on('scrollStart', () => { //滾動開始事件// console.log('scrollStart-')// })// this.bs.on('scroll', ({ y }) => { //監聽滾動事件// console.log('scrolling-')// })this.bs.on('scrollEnd', ({x,y}) => { //滾動結束事件this.scrollY = Math.abs(y)})},initTops(){const tops = []let top = 0tops.push(top)//收集每個item的盒子高度依次累加,我這里每個盒子175px,//所以數組[0, 175, 350, 525, 700, 875, 1050, 1225, 1400, 1575, 1750, 1925, 2100, 2275, 2450, 2625, 2800, 2975, 3150, 3325, 3500, 3675, 3850, 4025, 4200, 4375, 4550, 4725, 4900, 5075, 5250, 5425]const lis = this.$refs.list.getElementsByClassName('scroll-item')//偽數組Array.from(lis).forEach(li=>{top += li.clientHeighttops.push(top)})console.log(tops)//更新數據this.tops = tops},clickHandler (index) {//點擊左側側列表滑動到對應的位置const y = -this.tops[index]this.bs.scrollTo(0,y,100) //持續時間0.1s}}

總結

以上是生活随笔為你收集整理的vue中实现美团双级联动菜单的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。