小程序 view下拉滑动导致scrollview滑动事件失效

小程序页面需要滑动功能

下拉时滑动,展示整个会员卡内容, 下拉view里包含了最近播放:有scrollview,加了下拉功能后,scrollview滑动失败了。

 

<view class="cover-section" catchtouchstart="handletouchstart" catchtouchmove="handletouchmove"
        catchtouchend="handlettouchend"
        style="transform:{{coverTransform}};transition:{{coverTransition}};">

 <view class="latest-section">
      <view class="lat_title">最近播放</view>
      <scroll-view class="scroll1" scroll-x enable-flex="true">
        <view class="item" wx:for="{{playlist}}">
          <image class="item-img" src="{{item.song.al.picUrl?item.song.al.picUrl:'/static/images/recommendSong/02.jpg'}}"/>
          <text class="item-value">{{item.song.al.name}}</text>
        </view>
      </scroll-view>
</view>
</view

 

问题所在:父元素使用了touchstart,touchmove,touchend三个事件,导致作为子元素的scroll-view组件无法滑动
解决办法:父元素绑定touchstart事件时不要使用catch绑定,使用capture-bind:touchstart="fn"绑定,也就是捕获模式,touchmove和touchend还是使用catch绑定
小知识1:为什么不用bind绑定touchstart,touchmove,touchend呢,因为使用bind会导致拖动元素时元素卡顿问题
小知识2:为什么touchmove和touchend不需要更改为使用capture-bind绑定呢,这个我试了一下,会导致scroll-view滑动事件和touchmove事件冲突,然后你滑动scroll-view组件时你添加了touchmove的那个元素(这是是scroll-view的父元素)也会动

解决:

catchtouchstart="handletouchstart" 改成:

capture-bind:touchstart="handletouchstart" 

滚动视图滑动正常了。

<view class="cover-section" capture-bind:touchstart="handletouchstart" catchtouchmove="handletouchmove"
        catchtouchend="handlettouchend"
        style="transform:{{coverTransform}};transition:{{coverTransition}};">
 
<view class="latest-section">
      <view class="lat_title">最近播放</view>
      <scroll-view class="scroll1" scroll-x enable-flex="true">
        <view class="item" wx:for="{{playlist}}">
          <image class="item-img" src="{{item.song.al.picUrl?item.song.al.picUrl:'/static/images/recommendSong/02.jpg'}}"/>
          <text class="item-value">{{item.song.al.name}}</text>
        </view>
      </scroll-view>
</view>
</view>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值