Last active
May 16, 2020 08:59
-
-
Save mcsolha/fe1f900da8c00ee00fd34fb81ccfed68 to your computer and use it in GitHub Desktop.
This file contains 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 characters
function onHold(el, cb) { | |
let interval; | |
el.addEventListener('mousedown', () => interval = setInterval(() => requestAnimationFrame(cb), 10)); | |
el.addEventListener('mouseup', () => clearInterval(interval)); | |
el.addEventListener('mouseleave', () => clearInterval(interval)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment