Socket
Socket
Sign inDemoInstall

touchsweep

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    touchsweep

Super tiny vanilla JS module to detect swipe direction


Version published
Maintainers
1
Install size
21.6 kB
Created

Readme

Source

Travis CI Github Build Codacy Badge Codebeat Badge CodeFactor Badge DeepScan grade Analytics

TouchSweep

Super tiny vanilla JS module to detect swipe direction and trigger custom events accordingly.

Visitor stats

GitHub stars GitHub forks GitHub watchers GitHub followers

Code stats

GitHub code size in bytes GitHub repo size GitHub language count GitHub top language GitHub last commit

Install

npm i touchsweep

or

yarn add touchsweep

Usage

import TouchSweep from 'touchsweep';

const area = document.getElementById('swipe-area');
const data = {
	value: 1
};
const touchThreshold = 20;

const touchSwipeInstance = new TouchSweep(area, data, touchThreshold);

// Then listen for custom swipe events and do your magic:

area.addEventListener('swipeleft', event => {
	// You have swiped left
	// Custom event data is located in event.detail
});

area.addEventListener('swiperight', event => {
	// You have swiped right
	// Custom event data is located in event.detail
});

area.addEventListener('swipedown', event => {
	// You have swiped down
	// Custom event data is located in event.detail
});

area.addEventListener('swipeup', event => {
	// You have swiped up
	// Custom event data is located in event.detail
});

area.addEventListener('tap', event => {
	// You have tapped
	// Custom event data is located in event.detail
});

Options and default settings

The module constructor accepts three (3) arguments:

  • element: A HTML Element. Default is document.body
  • eventData: A plain JS object. Default is {}
  • threshold: How many pixels to count until an event is fired. Default is 40

API

TouchSweep provides a minimal API for you to use.

The TouchSwipe instance exposes two public methods which allow you to add or to remove all event listeners responsible for the module functionality.

This is useful in cases where you want to remove the TouchSwipe container/area from the DOM and prevent possible memory leaks by removing all event listeners related to this DOM element.

In order to remove all previously attached event listeners:

touchSwipeInstance.unbind();

In order to add all previously removed event listeners:

touchSwipeInstance.bind();

Supported Browsers

Currently all evergreen browsers are supported.

Demo

There is a simple demo illustrating how the TouchSweep library works.

Check it out here

LICENSE

MIT


Connect with me:


Support and sponsor my work:

Keywords

FAQs

Last updated on 30 Sep 2022

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