@three11/istouch
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

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

Package Sidebar

Install

npm i @three11/istouch

Weekly Downloads

8

Version

2.0.0

License

MIT

Unpacked Size

12.6 kB

Total Files

13

Last publish

Collaborators

  • scriptex
  • alpanayotov