微信小程序 - 实现左右菜单联动功能

  今天给大家分享一下如何实现微信小程序左右菜单栏联动效果(相关代码模块我已单独整理放到github上面了,欢迎前来start),具体过程如下:

效果图:

在这里插入图片描述

github地址:https://github.com/sunshime/weChatSkill

一、wxml文件

  这里需要注意的一点是:右边列表循环的那一项必须要加上 id="scroll-{ {index}}" ,少了这个是无法实现左边联动右边的效果的,这个坑我踩了很多次,所以在这里重点强调一下。

<!-- 实现左右联动效果 -->
<view class="link">
	<!-- 左边 -->
	<scroll-view class="left" scroll-y scroll-with-animation scroll-top="{
  {scrollTops}}">
		<view class="item {
  {tabCur===index?'active':''}}" wx:for="{
  {list}}" wx:key="index" data-index="{
  {index}}" bindtap="tabNav">{
  {item.name}}</view>
	</scroll-view>

	<!-- 右边 -->
	<scroll-view class="right" scroll-y scroll-with-animation scroll-into-view="scroll-{
  {rightCur}}" bindscroll="scrollLink">
		<!-- 重点: id="scroll-{
  {index}}"  这个必须要有 不然实现不了左边联动右边的效果-->
		<view wx:for="{
  {list}}" wx:key="{
  {index}}" class="right-cont" id="scroll-{
  {index}}">
			<view class="title">{
  {item.name}}</view>
			<view class="content">
				<view class="list-item" wx:for="{
  {item.list}}" wx:key="{
  {indexs}}" wx:for-index="indexs" wx:for-item="items">{
  {items}}</view>
			</view>
		</view>
	</scroll-view>
</view>

二、wxss文件

.link {
  width: 100%;
  height: 100%;
  display: flex;
}

.left {
  width: 220rpx;
  /* 这里的高度可以写也可以不写,效果还是可以实现的,不过最好还是写上吧 */
  height: 100vh;
  background-color: rgb(229, 243, 243);
  text-align: center;
  color: 
  • 26
    点赞
  • 92
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值