小程序scroll-view实现左右联动效果

本文介绍如何在小程序中使用scroll-view组件实现左右联动的效果。在实际操作中遇到一个问题,当点击左侧导航栏倒数第二个项时,active类名错误地应用到了前一个项上,目前问题尚未解决,期待技术大神指点。
摘要由CSDN通过智能技术生成

<view class="context">
  <view class="left">
    <scroll-view scroll-y 
    style="height: {
   { height }}"
    scroll-top="{
   { navScrollTop }}"
    scroll-into-view="item{
   { currentIndex }}"
    >
      <view 
      wx:for="{
   { navList }}" 
      wx:key="index"
      data-id="item{
   {index}}"
      data-index="{
   { index }}"
      id="item{
   {index}}"
      class="{
   { currentIndex == index ? 'active' : '' }}"
      catchtap="changeNav"
      >
      {
   {
    item.title }}
      </view>
    </scroll-view>
  </view>
  <view class="right">
    <scroll-view scroll-y 
    style="height: {
   { height }}"
    scroll-with-animation
    scroll-into-view = "{
   { id }}"
    bindscroll='productScroll'>
      <view class="item" 
      wx:for="{
   { productList }}"
      wx:key="index"
      id='product-item{
   {index}}'
      >
        <view class="title"><text>{
   {
    item.title }}</text></view>
        <view class="list" 
        wx:for="{
   { item.list }}"
        wx:for-item="list"
        wx:key="index">
          <image src="{
   { list.imgURL }}"></image>
          <text>{
   {
    list.name }}</text>
        </view>
      </view>
    </scroll-view>
  </view>
</view>
.context {
   
  box-sizing: border-box;
  display: flex;
}
.context .left {
   
  box-sizing: border-box; 
}
.context .left scroll-view {
   
  height: 100%;
  flex-shrink: 0
}
.context .left view {
   
  font-size: 28rpx;
  height: 70rpx;
  line-height: 70rpx;
  background: #ccc;
  box-sizing: border-box;
  padding: 0 20rpx
}
.context .left view.active {
   
  color: #f00
}
.context .right {
   
  text-align: center;
  font-size: 30rpx;
  font-weight: 700;
  flex: 1;
  line-height: 50rpx;
}
.context .list {
   
  box-sizing: border-box;
  display: flex;
  align-items: center;
  padding: 16rpx 24rpx;
}
.context image {
   
  width: 120rpx;
  height: 120rpx;
}
Page({
   

  /**
   * 页面的初始数据
   */
  data: {
   
    navList: [
      {
    title: '家用电器' },
      {
    title: '家居用品' }, 
      {
    title: '电脑办公' }, 
      {
    title: '食品酒类' },
      {
    title: '家用电器' },
      {
    title: '家居用品' }, 
      {
    title: '电脑办公' }, 
      {
    title: '食品酒类' }, 
      {
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值