Use JS to detect touch-enabled device
npm i @three11/istouch
or
yarn add @three11/istouch
import isTouch from '@three11/istouch';
import { setTouchClass } from '@three11/istouch';
console.log(isTouch); // Returns true for touch-enabled devices
setTouchClass(); // Set the default "touch" or "notouch" className to the `html` element
By default, the module sets a classname to the <html>
tag.
If the device is touch-enabled, the classname is touch
.
If not - the classname is no-touch
.
You can overwrite these settings:
const el = document.getElementById('element');
const classNames = {
touch: 'is-touch-device',
notouch: 'is-not-touch-device'
};
setTouchClass(el, classNames);
MIT