Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@luckyshot
Last active December 14, 2015 16:29
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 luckyshot/5115177 to your computer and use it in GitHub Desktop.
Save luckyshot/5115177 to your computer and use it in GitHub Desktop.
Detect if is a touch device
/**
* TOUCH DEVICE
* Detects touch devices
* Usage: if (is_touch_device) { yes! }
*/
var is_touch_device = 'ontouchstart' in document.documentElement;
/**
* CSS class method
* Detects touch devices
*/
if ( !!('ontouchstart' in window) )
{
$('html').addClass( 'touch' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment