Skip to content

Instantly share code, notes, and snippets.

@Loac-fr
Created February 21, 2017 12:46
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 Loac-fr/4975c09e999c690d75800df78871f3e6 to your computer and use it in GitHub Desktop.
Save Loac-fr/4975c09e999c690d75800df78871f3e6 to your computer and use it in GitHub Desktop.
Touch and mouse "hack"
// from http://corlan.org/2012/02/15/quick-hack-to-deal-with-touch-and-mouse-events/
// not tested
function init() {
var el = document.getElementById('myDiv');
el.addEventListener('mousemove', onMouseMove);
el.addEventListener('touchmove', onTouchMove);
}
function onMouseMove(e) {
e.touches = [{clientX: e.clientX, clientY: e.clientY}];
onTouchMove(e);
}
function onTouchMove(e) {
//do something with e.touches[0].clientX or e.touches[0].clientY
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment