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
}







网友评论