Created
October 25, 2020 03:51
-
-
Save nihlton/cfeb311119998c075e1fbc48c4dba1dc to your computer and use it in GitHub Desktop.
Revisions
-
nihlton created this gist
Oct 25, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ export default function longPressEvents(callback, ms = 500) { let timeout = null const start = () => (timeout = setTimeout(callback, ms)) const stop = () => timeout && window.clearTimeout(timeout) return callback ? { onMouseDown: start, onMouseUp: stop, onMouseLeave: stop, onTouchStart: start, onTouchMove: stop, onTouchEnd: stop, } : {} }