关于小程序图片长按实现自定义功能

                  

在业务场景中会接触到长按图片实现自定义功能的需求,这次是长按图片跳转客服聊天,在小程序image标签是支持长按识别图片的,但是功能比较单一,且不支持编辑功能项

<image src="https://.jpg" mode="" show-menu-by-longpress="true" />

具体实现代码如下

html部分

<image 
@touchstart="touchstart" 
@touchend="touchend" src="https://new99.file.vipetc.com.cn/etc99/publicQrcode.jpg" 
mode=""
 />

js部分

 touchstart(e) { //创建全局定时器变量 time:null 
      console.log("touchstart");
     this.time =  setTimeout(() => {
        uni.showActionSheet({
          itemList: ["联系客服"],
          success: (res) => {
            console.log("选中了第" + (res.tapIndex + 1) + "个按钮");
            this.openCustomer();//客服事件
          },
          fail: function (res) {
            console.log(res.errMsg);
          },
        });
      }, 1000);//事件触发1s后触发事件,模拟长按
    },
    touchend() {//事件移除清除定时器
      console.log("touchend");
      
      clearTimeout(this.time);
    },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值