账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    小程序既能禁止swiper手动滑动不影响页面向上滑动又能点击swiper里面的按钮的方法
    41
    0

    手动禁止了,也能向上滑了,可是里面的bindtap事件触发不到了,有什么办法能解决呢

    <view class="shades">
      <view class="shade"></view>
      <swiper class="swiper_tuan" autoplay="true" vertical="{{true}}" interval="{{3000}}" duration="{{200}}">
        <block wx:for="{{group_order}}" wx:key="group_order">
          <swiper-item class="swiper_tuan_num">
            <view class="group">
              <view class='group_user'>
                <image class="head_img" src="{{item.avatar}}"></image>
                <text class="head_name">{{item.alias}}</text>
              </view>
              <view class='surplus'>
                <view class="surplus_text">还差
                  <text>{{item.cha_num}}人</text>拼成</view>
                <view class="shengyu">剩余{{item.end_time}}</view>
              </view>
              <view class="join_group" data-groupid="{{item.id}}" catchtap='tapBuyNow' id="1">去参团</view>
            </view>
          </swiper-item>
        </block>
      </swiper>
    </view>

    .shades{
    position: relative;
    background: #fff;
    }
    .shade{
    position: absolute;
    background: transparent;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 5
    }

    1
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    • 要禁止Swiper手动滑动但不影响页面向上滑动,并且可以点击Swiper里面按钮,可以使用以下方法:

      1. 在Swiper组件的onTouchStart事件中,检查当前触摸点是否在Swiper的边界之外。如果不在边界之外,则继续滑动。

      javascript Swiper.prototype.onTouchStart = function(e) { var touch = e.touches[0]; var swipeStartX = touch.clientX; var swipeStartY = touch.clientY; var swipeEndX = this.rightPosX; var swipeEndY = this.bottomPosY; if (swipeStartX < swipeEndX && swipeStartY < swipeEndY) { return; } // If you need to handle more cases, you can add more condition here. };

      1. 在Swiper组件的onTouchEnd事件中,如果Swiper的滑动已经停止,则不再阻止滑动。

      javascript Swiper.prototype.onTouchEnd = function(e) { var touch = e.touches[0]; var swipeStartX = touch.clientX; var swipeStartY = touch.clientY; var swipeEndX = this.rightPosX; var swipeEndY = this.bottomPosY; if (swipeStartX > swipeEndX && swipeStartY > swipeEndY) { return; } // If you need to handle more cases, you can add more condition here. };

      1. 在Swiper组件的onTouchMove事件中,判断滑动的边界,阻止滑动。

      javascript Swiper.prototype.onTouchMove = function(e) { var touch = e.touches[0]; var swipeStartX = touch.clientX; var swipeStartY = touch.clientY; var swipeEndX = this.rightPosX; var swipeEndY = this.bottomPosY; if (swipeStartX < swipeEndX && swipeStartY < swipeEndY) { return; } // If you need to handle more cases, you can add more condition here. };

      以上代码只是一个基础的示例,你可能需要根据你的具体需求进行修改和扩展。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部