Last active
December 22, 2015 00:59
-
-
Save mandelbro/6393456 to your computer and use it in GitHub Desktop.
Touch event detection is tricky now that desktop browsers are reporting touch events in windows. This script first checks for MS Pointer events, which combine touch and click events for devices like the Surface or HP touchsmart laptops. Otherwise it checks for HTML5 standard touch events AND the window.orientation object, this ensures the user i…
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
// this will pull events for a grabber action: down, up, and move | |
var getGrabberEvents = function() { | |
// run through possible events | |
if(window.navigator.msPointerEnabled) { // windows specific | |
// see http://msdn.microsoft.com/en-us/library/ie/hh673557(v=vs.85).aspx | |
return 'MSPointerDown MSPointerUp MSPointerMove'; | |
} else if(window.orientation && Modernizr.touch) { // html5 standard touch events | |
// if you don't want to use modernizr, see this thread: | |
// http://stackoverflow.com/questions/14267598/is-there-a-more-elegant-way-to-detect-touch-events-support-and-assign-either-a | |
return 'touchstart touchend touchmove'; | |
} else { // otherwise return click events | |
return 'mousedown mouseup mousemove'; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment