javascript - 如何用 React js 模拟长按?
问题描述
我想用点击事件触发长按事件。react js有什么办法吗?
与此相近的是 jQuery trigger() 函数。但我想要触发器(“longPress”)之类的东西,或者用左键点击打开右键菜单。两者都提到(长按触发器/打开右键菜单)对我来说是理想的
解决方案
像这样的东西怎么样:
const myComponent = () => {
let clickHoldTimer = null;
const handleMouseDown = () => {
clickHoldTimer = setTimeout(() => {
//Action to be performed after holding down mouse
}, 1000); //Change 1000 to number of milliseconds required for mouse hold
}
const handleMouseUp = () => {
clearTimeout(clickHoldTimer);
}
return (
<div onMouseDown={handleMouseDown} onMouseUp={handleMouseUp} />
)
}
推荐阅读
- vue.js - 在元素上设置 Vuejs 过渡以让其他元素出现
- android - 具有绝对位置的 FlatList 子项不起作用?
- django - 将 csrf_token 直接传递给 ajax 发布数据是否安全?
- android - 三星设备中的 Webview 崩溃:Chrome 84
- flutter - 颤振地理定位器返回未处理的异常
- javascript - 为什么它显示未定义,如果 handleChange 本身有值
- javascript - 想要替换js中的字符串
- xcode - Xcode 不允许我使用 setRootViewController
- r - RStudio 云:R 4.0.0 Rmarkdown
- amazon-product-api - 是否有可用于在您自己的帐户中添加地址的亚马逊 API 或 SDK?