Socket
Socket
Sign inDemoInstall

node-touch

Package Overview
Dependencies
64
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-touch

Extra touch events and hover behaviour for touch devices.


Version published
Weekly downloads
30
increased by130.77%
Maintainers
1
Install size
10.0 MB
Created
Weekly downloads
 

Readme

Source

node-touch

npm install node-touch

Extra touch events and hover behaviour for touch devices.

require('node-touch')();
<div class="touch">Example</div>

In order to use the features, you have to call the module once in the beginning and create the dom elements with the touch class.

hover

div { ... }
div.hover { ... }

On touch devices, the hover behaviour is quite crappy. With this module, if you use the .hover class instead of the :hover pseudoclass, on a touch device the class will be applied when the element is touched on the screen, and on a non-touch device it will act as :hover. example.

tap

var button = document.createElement('button').
button.classList.add('touch');
document.body.appendChild(button);

button.addEventListener('tap', function (event) {
  console.log('Tapped!');
}, false);

You can use the tap event just as a normal event. It is sort of the touch equivalent of click.

touchleave

var div = document.querySelector('div');

div.addEventListener('touchleave', function (event) {
  console.log('Left!');
}, false);

The event fires when the finger left the element.

swipe

You can add listeners to swipe events. There are three type of swipe events.

div.addEventListener('swipestart', function (event) {});

div.addEventListener('swipemove', function (event) {});

div.addEventListener('swipeend', function (event) {});

The event object's important properties are:

  • direction: RIGHT, LEFT, UP, DOWN
  • delta: how much pixel it moved from the starting touch (relative to the direction)
  • startTouch: the starting touch object
  • prevTouch: the previous touch object
  • changedTouch: the latest touch object

window.isTouchDevice

This module sets a global Boolean that just tells you whether the user is on a touch device. It can be useful!

Keywords

FAQs

Last updated on 04 Aug 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc