Created
September 25, 2012 16:52
-
-
Save eklimcz-zz/3783097 to your computer and use it in GitHub Desktop.
Cross browser touch event wireup
This file contains 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
function inferInputModel() { | |
if (window.navigator.msPointerEnabled) { | |
return 'pointer'; | |
} else if (window.ontouchstart !== undefined) { | |
return 'touch'; | |
} else { | |
return 'unknown'; | |
} | |
} | |
switch (inferInputModel()) { | |
case 'pointer': | |
element.addEventListener('MSPointerDown', msStart); | |
element.addEventListener('MSPointerOut', msStop); | |
document.addEventListener('MSPointerUp', msStop); | |
document.addEventListener('MSPointerCancel', msStop); | |
document.addEventListener('MSHoldVisual', preventDefault); | |
break; | |
case 'touch': | |
element.addEventListener('touchstart', touchStart); | |
document.addEventListener('touchend', touchStop); | |
element.addEventListener('mousedown', mouseStart); | |
element.addEventListener('mouseout', mouseStop); | |
document.addEventListener('mouseup', mouseStop); | |
break; | |
default: | |
element.addEventListener('mousedown', mouseStart); | |
element.addEventListener('mouseout', mouseStop); | |
document.addEventListener('mouseup', mouseStop); | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please give an Example how to implement these !