美文网首页
IOS禁止长按复制、下载功能

IOS禁止长按复制、下载功能

作者: 码农私房菜 | 来源:发表于2022-08-28 17:48 被阅读0次

ios手机开启长按

.img-content {
    
    // 开始长按菜单
    -webkit-touch-callout: default;
    // 开启选中文本
    -webkit-user-select: auto;
    -moz-user-select: auto;
    -ms-user-select: auto;
    user-select: auto;
}

ios手机关闭长按

.img-content {
    
    // 开始长按菜单
    -webkit-touch-callout: none;
    // 开启选中文本
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
<div
   className="img-content"
   onTouchStart={touchStart}
   onTouchMove={touchMove}
   onTouchEnd={touchEnd}
/>

监听长按事件

    let flag = 0
    let timer = null
    const touchStart = () => {
        timer = setInterval(() => {
            if (flag >= 300) {
                console.log(flag, '长按')
                timer && clearInterval(timer)
                return
            }
            flag += 100
        }, 100)
    }
    const touchMove = () => {
        console.log(flag, '移动重新初始数据')
        if (timer) {
            clearInterval(timer)
            flag = 0
        }
    }
    const touchEnd = () => {
        timer && clearInterval(timer)
        flag = 0
    }


相关文章

网友评论

      本文标题:IOS禁止长按复制、下载功能

      本文链接:https://www.haomeiwen.com/subject/qacknrtx.html