Skip to content

Instantly share code, notes, and snippets.

@xgrommx
Forked from mattpodwysocki/tap-and-hold.js
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save xgrommx/15bfa2709db39988fd1f to your computer and use it in GitHub Desktop.

Select an option

Save xgrommx/15bfa2709db39988fd1f to your computer and use it in GitHub Desktop.
const touchStart = Rx.Observable.fromEvent(window, 'touchstart').timestamp();
const touchMove = Rx.Observable.fromEvent(window, 'touchmmove');
const touchEnd = Rx.Observable.fromEvent(window, 'touchend').timestamp();
const touchAndHold = touchStart
.flatMap(() => touchEnd.takeUntil(touchMove), (x, y) => { start: x.timestamp, end: y.timestamp })
.filter(ts => (ts.end - ts.start) / 1000 > 2);
const subscription = touchAndHold.subscribe(
() => console.log('touch and hold!')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment