istouch

GitHub release GitHub issues GitHub last commit Build Status npm npm Analytics

isTouch

Use JS to detect touch-enabled device

Install

npm i @three11/istouch

or

yarn add @three11/istouch

Usage

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

Customization

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);

License

MIT

  • Hire me onBraintrust
  • Hire me onToptal

Go back

Send me your message