Created
February 21, 2017 12:46
-
-
Save Loac-fr/4975c09e999c690d75800df78871f3e6 to your computer and use it in GitHub Desktop.
Touch and mouse "hack"
This file contains hidden or 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
// 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