小程序实现左右切换滑动列表思路

实现目标

  1. 可左右滑动切换列表;
  2. 点击分类菜单切换到相应的列表;
  3. 每个列表都可以上拉加载及下拉刷新;

结果展示

在这里插入图片描述

思路

通过使用scroll-view组件来实现顶部的菜单列表、多个列表的左右滑动实现父组件及滚动列表,同时监听触摸相关事件来处理左右滑动整个列表而不是滑一部分移动一部分、对列表上下滚动和左右滑动的优化及配合translateY实现scroll-view组件的上拉加载和下拉刷新。

代码实现

基本的wxml文件实现布局:

<view class="page-con">
  <scroll-view class="nav-list" scroll-x="{
    {true}}" scroll-into-view="{
    {navList[activeNavIndex].name}}" scroll-with-animation="true" scroll-anchoring="true">
    <view id="{
    {item.name}}" class="nav-item {
    {activeNavIndex === index ? 'active' : ''}}" wx:for="{
    {navList}}" wx:key="index" bindtap="switchPage" data-navIndex="{
    {index}}">{
  {item.name}}</view>
  </scroll-view>
  <scroll-view class="list-con" scroll-x="{
    {canSwitch}}" scroll-into-view="{
    {navList[activeNavIndex].name}}" scroll-with-animation="true" scroll-anchoring="true">
    <scroll-view id="{
    {item.name}}" class="list-item" wx:for="{
    {navList}}" wx:key="index" scroll-y="true" bindtouchstart="touchStart" bindtouchmove="touchMove" bindtouchend="touchEnd" bindtouchcancel="touchCancel" bindscroll="listScroll" bindscrolltolower="bottomLoad" style="transform: translateY({
      {
      freshDistance}}px)">
      <view class="top-fresh" hidden="{
    {!item.isFresh}}"></view>
      <view class="card-item" wx:for="{
    {item.cardNum}}" wx:for-item="cardItem" wx:for-index="cardIndex" wx:key="cardIndex">{
  {item.name}}-{
  {cardIndex}}</view>
      <view class="top-fresh" hidden="{
    {!item.showLoading}}"></view>
    </scroll-view>
  </scroll-view>
  • 3
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值