I would suggest using modernizr and using its media query features.
if (Modernizr.touch){
// bind to touchstart, touchmove, etc and watch `event.streamId`
} else {
// bind to normal click, mousemove, etc
}
However, using CSS, there are pseudo class like, for example in Firefox. You can use :-moz-system-metric(touch-enabled). But these features are not available for every browser.
For Apple devices, you can simple use:
if(window.TouchEvent) {
//.....
}
Especially for Ipad:
if(window.Touch) {
//....
}
But, these do not work on Android.
Modernizr gives feature detection abilities, and detecting features is a good way to code, rather than coding on basis of browsers.
Modernizer adds classes to the HTML tag for this exact purpose. In this case, touch
and no-touch
so you can style your touch related aspects by prefixing your selectors with .touch. e.g. .touch .your-container
. Credits: Ben Swinburne