h5端长按图片分享功能

	在移动h5开发中,经常会遇到需要长按图片可以保存的本地的需求。

在标签中写入触摸事件

<div class="codeBox" @touchstart="touchStart()" @touchend="touchEnd()"></div>

然后在methods里面定义方法

        touchEnd(){
            //手指离开
            clearTimeout(this.Loop);
        },
        touchStart(){
            //手指触摸
            clearTimeout(this.Loop); //再次清空定时器,防止重复注册定时器
            this.Loop = setTimeout(() => {
                // console.log(1222)
                this.downImg()
            },1000)
        },
         // 下载
        downImg() {
            if(!window.plus) return;
                plus.gallery.save(this.imgUrl, function () {
                    console.log('保存成功');
                },function(){
                    console.log('保存失败');
            });
        }

在页面中长按之后的效果在这里插入图片描述

Logo

前往低代码交流专区

更多推荐