Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vanilla-swipe

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vanilla-swipe

Tiny vanilla JS library to detect swipe direction.

  • 2.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32K
decreased by-19.4%
Maintainers
1
Weekly downloads
 
Created
Source

vanilla-swipe

Tiny vanilla JS library to detect swipe direction.

Build Status npm version covarage

Live demo 👉here

Types

type ConstructorProps = {
  element?: HTMLElement | null;
  target?: HTMLElement | null;
  delta?: number | 10;
  rotationAngle?: number | 0;
  mouseTrackingEnabled?: boolean | false;
  touchTrackingEnabled?: boolean | true;
  preventDefaultTouchmoveEvent?: boolean | false;
  preventTrackingOnMouseleave?: boolean | false;
  onSwipeStart?: EventHandler;
  onSwiping?: EventHandler;
  onSwiped?: EventHandler;
  onTap?: EventHandler;
};

type EventHandler = {
  (e: Event, data: EventData): void;
};

type EventData = {
  deltaX: number;
  deltaY: number;
  absX: number;
  absY: number;
  duration: number; // ms
  velocity: number; // (px/ms)
};

Props

  • element - target event trigger
  • target - additionally target event trigger, if specified with the element, will be used by all handlers to trigger the action
  • delta - minimal distance in px before a swipe starts
  • rotationAngle - rotation angle
  • mouseTrackingEnabled - enable mouse tracking
  • touchTrackingEnabled - enable touch tracking
  • preventDefaultTouchmoveEvent - prevent default touch events while touching
  • preventTrackingOnMouseleave - triggered onSwiped callback when the event loses the element's focus
  • onSwipeStart - triggered on swipe start (if the delta is passed)
  • onSwiping - triggered during swipe
  • onSwiped - triggered after swipe
  • onTap - triggered when the swipe value is less than the minimum distance (delta)

Methods

  • init(): void
  • update(options: ConstructorProps): void
  • destroy(): void

Install

npm install vanilla-swipe

Examples

import VanillaSwipe from 'vanilla-swipe';

const VS = new VanillaSwipe({
  element: document.getElementById('some-id'),
  onSwiping: handler,
  onSwiped: handler,
  mouseTrackingEnabled: true,
});

VS.init();

function handler() {
  console.log(...arguments); // -> Event, { deltaX, deltaY, absX, absY, duration, velocity }
}

Run project

npm i
npm start

Tests

npm test

Coverage

npm run test:coverage

Keywords

FAQs

Package last updated on 15 Apr 2020

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc