Coder Social home page Coder Social logo

wanjarus / touchsweep Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scriptex/touchsweep

0.0 1.0 0.0 64 KB

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

Home Page: http://npm.im/touchsweep

License: MIT License

JavaScript 100.00%

touchsweep's Introduction

GitHub release GitHub issues GitHub last commit Github file size Build Status npm npm Analytics Greenkeeper badge

TouchSweep

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

This module works on touch-enabled devices only.

Install

npm i touchsweep

or

yarn add touchsweep

or

just download this repository and use the files located in dist folder.

Usage

import TouchSweep from 'touchsweep';

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

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

Supported Browsers

Currently all evergreen browsers are supported. IE 10+ support is planned in the near future.

Demo

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

Check it out here

LICENSE

MIT

touchsweep's People

Contributors

scriptex avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.