原理
首先是获取数据,并且获取数据的长度(需要根据长度来计算元素的高度),通过遍历数据的内容通过题目和元素个数的相加得到高度,当消失高度小于等于某个元素的高度就设定索引值给左边的菜单目录实现右边滑动左边联动,左边的菜单点击事件联动比较简单就不说
代码实现
- wxml
<view class="menu">
<view class="left-box">
<scroll-view class="left_menu" scroll-with-animation scroll-y="true" scroll-into-view="{
{leftViewId}}">
<text class="menu-item {
{index==currentIndex?'menu-active':''}}" wx:for="{
{navList}}" wx:key="this" data-id="menu{
{index}}" data-i="{
{index}}" bindtap="changeMenu">{
{item.c_name}}</text>
</scroll-view>
</view>
<view class="right-box">
<scroll-view class="right_menu" scroll-y='true' scroll-with-animation scroll-into-view