Skip to content

Instantly share code, notes, and snippets.

@mcsolha
Last active May 16, 2020 08:59
Show Gist options
  • Save mcsolha/fe1f900da8c00ee00fd34fb81ccfed68 to your computer and use it in GitHub Desktop.
Save mcsolha/fe1f900da8c00ee00fd34fb81ccfed68 to your computer and use it in GitHub Desktop.
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