سؤال

Is there a way to detect if the user is on a touchscreen device? I want to change some HTML/jquery based on that fact (more specifically, jquery capSlide to show caption on touchscreen devices while hiding it on desktop). What would be the easiest way to accomplish this?

هل كانت مفيدة؟

المحلول

This one-liner should suffice.

var is_touch_device = 'ontouchstart' in document.documentElement;

Taken from this Stack Overflow answer here: https://stackoverflow.com/a/6447935/1585455

Your conditional should look something like this:

if(is_touch_device) { /* your code */ }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top