Skip to content

Instantly share code, notes, and snippets.

@tvandervossen
Created November 2, 2010 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tvandervossen/660306 to your computer and use it in GitHub Desktop.
Save tvandervossen/660306 to your computer and use it in GitHub Desktop.
Add mouse events to your touch app
var start = 'touchstart', move = 'touchmove', end = 'touchend';
if (!device.hasTouch) { start = 'mousedown'; move = 'mousemove'; end = 'mouseup'; }
element.addEventListener(start, this.ontouchstart.bind(this), false);
element.addEventListener(move, this.ontouchmove.bind(this), false);
element.addEventListener(end, this.ontouchend.bind(this), false);
element.addEventListener('touchcancel', this.ontouchcancel.bind(this), false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment