Web Gesture Events

Overview

Web Gesture Events

A library that brings high-level asynchronous gesture events to the web by extending the standard addEventListener interface. ☝🏾 📱

Demo

version downloads license

Table of Contents

Installation

npm install web-gesture-events

Usage

Basic

Add event listeners as you would using the addEventListener interface. The GestureEvent interface passed as the argument to all gesture events is an extension of the TouchEvent interface. Which means all the properties you are used to are the same with the addition of a few properties. Rotation and Scale on iOS have been overwritten since they are not considered standard

...
import 'web-gesture-events'; // top level import only side-effects
...

import {SwipeEvent} from 'web-gesture-events';

window.addEventListener('swipe', (ev) => {
    console.log(ev.direction, ev.velocity); // direction and instantaneous velocity
}

Config Options

Config options can be set on the global GestureProvider interface available on the window or by specifying a data-attribute on a DOM element.

">
window.gestureProvider.config.minPointers = 2;
// OR

  

API Documentation

Gesture Provider Config

Property Type Description
minPointers number Minimum number of touch points necessary before events are fired.
longPressDuration number Minimum duration in milliseconds for a touch to be persisted to fire a single LongPressEvent.
tapDelay number Maximum time in milliseconds that can pass between taps.
numberOfTaps number Number of taps required before tap events are fired.

Config Attributes

Data- prefixed attributes recognised on DOM elements.

Property Type Description
data-minpointers string Minimum number of touch points necessary before events are fired.
data-longpressduration string Minimum duration in milliseconds for a touch to be persisted to fire a single LongPressEvent.
data-tapdelay string Maximum time in milliseconds that can pass between taps.
data-numberoftaps string Number of taps required before tap events are fired.

GestureEvent

Property Type Description
gestureTarget EventTarget The element that the primary pointer TouchStart event targeted.
x number Horizontal position of the primary pointer relative to the viewport.
y number Vertical position of the primary pointer relative to the viewport.

LongPressEvent

Property Type Description
duration number Duration of the long press event.

SwipeEvent

Property Type Description
types "swipestart", "swipe", "swipeend" Events fired over the lifecycle of a swipe.
velocity number Instantaneous velocity of user swipe. In case of swipeend velocity equals average velocity of swipe.
direction "up", "down", "left" or "right" Direction of the user swipe relative to the gesture origin.

PanEvent

Property Type Description
types "panstart", "pan", "panend" Events fired over the lifecycle of a pan.
velocity number Instantaneous velocity of user pan. In case of panend velocity equals average velocity of swipe.
translation Translation Object that contains x and y movements of user gesture relative to gesture origin and viewport.

RotateEvent

Property Type Description
types "rotatestart", "rotate", "rotateend" Events fired over the lifecycle of a rotation.
rotation number Rotation about the anchor (primary pointer) in radians.
rotationDeg number Rotation about the anchor (primary pointer) in degrees.
anchor Anchor Object that contains x and y positions of rotation anchor point relative to gesture origin and viewport.

PinchEvent

Property Type Description
types "pinchstart", "pinch", "pinchend" Events fired over the lifecycle of a pinch.
scale number Scale factor relative to primary and secondary touch points' distance.

Remarks

There are a few potential drawbacks I haven't been able to overcome. For example the data-attribute config options might not work if a gesture event listener uses bubbling. Also even though these gesture events are asynchronous there is still the problem that the browser currently does not offer a way to query if event listeners exist on an element anywhere in the DOM tree. Meaning events are always fired regardless of if an event listener was detected or not. Also these events are not trusted events so do bare that in mind whenever using these events to accomplish things that require user interaction such as toggling fullscreen or resuming an audio context.

Credits

  1. React Native Gesture Handler
  2. Introduction to events
  3. Touch Events
You might also like...

PoGOEvents is a Scriptable widget that displays current and upcoming Pokemon GO events.

PoGOEvents is a Scriptable widget that displays current and upcoming Pokemon GO events.

PoGOEvents PoGOEvents is a Scriptable widget that displays current and upcoming Pokemon GO events. All event data is gathered from from ScrapedDuck, w

Nov 12, 2022

A TypeScript friendly event emitter with easy re-emitting events

remitter A TypeScript friendly event emitter with easy re-emitting events. Install npm add remitter Usage import { Remitter } from "remitter"; interf

Dec 28, 2022

New Discord.JS v14 Slash and Prefix Commands handler with Events. Check it out now!

New Discord.JS v14 Slash and Prefix Commands handler with Events. Check it out now!

Discord.js v14 Command-Handler Commands, Events, Permissions and Cooldown Handlers for Discord.js v14 bot ~ Made by Lynx Discord.js v14 (dev version)

Dec 19, 2022

Custom events 'movestart', 'move' and 'moveend' for jQuery.

#jquery.event.move Move events provide an easy way to set up press-move-release interactions on mouse and touch devices. UPDATE 2.0: move events are n

Apr 20, 2022

A jQuery plugin that lets you attach callbacks to useful image loading events.

waitForImages Copyright (c) 2011-2018 Alexander Dickson @alexdickson Licensed under the MIT licenses. http://alexanderdickson.com Donate! Overview Pro

Dec 28, 2022

This project will be a basic website that allows users to add/remove books from a list. The main objective is to understand how to use JavaScript objects and arrays and dynamically modify the DOM and add basic events.

Awesome-books Awesome Books This project will be a basic website that allows users to add/remove books from a list. This project is part of the Microv

Oct 3, 2022

A javascript library to animate elements on scroll page events

ScrollJS by Sam Sirianni ScrollJS is a library written in Javascript. With ScrollJS you can animate elements on scroll events. Visit the ScrollJS webs

Mar 21, 2021

jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested on Firefox/Chrome/Maxthon/iPhone/Android. Very light 7ko min.js and 1Ko min.css.

Nice-Scrollbar Responsive jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested

Jan 18, 2022

A bot to propose events for a discord server.

Project Name Project Description Live Version This page is not yet deployed. Feedback and Bugs If you have feedback or a bug report, please feel free

Dec 17, 2022
Releases(v0.0.0-alpha)
Owner
Nathan Johnson
PWA enthusiast. Building the interactive web one library at a time. 🚀👨🏾‍💻
Nathan Johnson
AppRun is a JavaScript library for developing high-performance and reliable web applications using the elm inspired architecture, events and components.

AppRun AppRun is a JavaScript library for building reliable, high-performance web applications using the Elm-inspired architecture, events, and compon

Yiyi Sun 1.1k Dec 20, 2022
Adds `swiped` events to the DOM in 0.7k of pure JavaScript

swiped-events A 0.7k script that adds swiped-left, swiped-right, swiped-up and swiped-down events to the DOM using CustomEvent and pure JS. Based on t

John Doherty 493 Jan 8, 2023
Event scheduler is a simple app for viewing the events happening around you

Event scheduler is a simple app for viewing the events happening around you. User can also create their event and include a location. Location can also be marked as hidden(strictly by IV). Built with React and Styled Components

Anselem Odimegwu 3 Mar 29, 2022
Integrate Railway Project events with Telegram Chat/Channel using Railway Webhooks

Railway to Telegram Integrate Railway Project events with Telegram Chat/Channel using Railway Webhooks! One Click Self Deploy Manual Self Deploy Fork

Agampreet Singh 9 Jul 5, 2022
Timers for Lost Ark bosses, islands, events, wandering merchants and more! Never miss an event again.

Timers for Lost Ark bosses, islands, events, wandering merchants and more! Never miss an event again. LostArkTimer.app Website Website Features Event

Joshua Kuan 28 Oct 17, 2022
It's the ragemp server middlewares for events

RageMP Server Middlewares Данный пример промежуточных функций разработан, чтобы любые другие разработчики могли им пользоваться. Документация: App App

null 8 Sep 8, 2022
An open-source analytics library to measure user events the hassle-free way.

walker.js The walker.js is an open-source event tracker for all tools. Easy, standardized & flexible. Capture user events in the browser by setting HT

elbwalker 181 Dec 22, 2022
A JavaScript library for adding ripple effects to HTML elements based on mouse events.

About project Ripplejs is an open source javascript library created for the purpose of adding ripple effects to html elements based on mouse events. L

Udezue Oluomachi Chimaobi 7 May 10, 2022
A project for experimenting with Server Sent Events (SSE), a way of communication going from server to client.

A project for experimenting with Server Sent Events (SSE), a way of communication going from server to client.

Italo Menezes 4 May 16, 2022
NFC based attendance recording app for offline events.

NFC Entry NFC based attendance recording app for offline events. Capture proof of presence in offline events using NFC enabled ID Cards and a smartpho

Vaibhav Garg 9 Sep 24, 2022