微信小程序 利用swiper + css 实现购物车商品删除功能

要实现的购物车效果如下:

图片描述

小程序通过bind与catch绑定事件,没有event.stopPropagation()方法。
    bind:不会阻止冒泡事件向上冒泡,
    catch:可以阻止冒泡事件向上冒泡
用touchstart、touchmove、touchend实现滑块效果,无法动态js控制何时冒泡何时阻止冒泡,就会出现用bind时,左右上下滑动乱窜;用catch,商品区域只能左右滑动,无法上下滚动

而小程序提供的swiper通过css就可以实现删除滑块效果,同时不影响页面的正常滚动。具体如下

 <!--html-->
    <view class="goodsList ">
            <!--商品-->
            <view class="goodsItem">
                <swiper previous-margin = "610rpx">
                    <swiper-item class="goodsMsg">
                        <!--xxx商品信息区域xxx-->
                    </swiper-item>
                    <swiper-item class="delBtn">
                        <view>删除</view>
                    </swiper-item>
                </swiper>
            </view>
    </view>
    


  /*css*/
     .goodsItem swiper{
         height:230rpx;
     }
     .goodsItem .goodsMsg{
        height:170rpx;
        padding:30rpx 0rpx;
        width:750rpx!important;
        background:#fff;
        margin-left:-610rpx;
     }
     .goodsItem .goodsMsg .delBtn{
        color:#fff;
        line-height:230rpx;
        font-size:30rpx;
        text-align: center;
        display:flex;
        display:-webkit-flex;
        justify-content: flex-end;
      }
      .goodsItem .delBtn view{
        width:140rpx;
        background:#ff4300;
      }
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值