Socket
Socket
Sign inDemoInstall

ng-swipe

Package Overview
Dependencies
5
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ng-swipe

A lightweight Angular directive to detect swipes on touchscreen devices.


Version published
Weekly downloads
275
decreased by-15.64%
Maintainers
1
Install size
158 kB
Created
Weekly downloads
 

Readme

Source

Angular Swipe

A lightweight Angular directive to detect swipes on touchscreen devices.

Installation

npm install ng-swipe --save

Usage

Import SwipeModule to your module:

import { SwipeModule } from 'ng-swipe';

@NgModule({
  imports: [
    SwipeModule
  ],
})

Add ngSwipe directive to your DOM element and listen to swipeMove or swipeEnd events that are emitted when swipe happens on this element.
Both events correspond to SwipeEvent interface, which contains two fields:
direction: 'y' | 'x' - defines swipe direction
distance: number - defines swipe length in pixels

import { SwipeEvent } from 'ng-swipe';

@Component({
  selector: 'app',
  template: `
    <div 
      ngSwipe 
      (swipeMove)="onSwipeMove($event)" 
      (swipeEnd)="onSwipeEnd($event)"
    >My test element for swipe</div>
  `
})
export class AppComponent {
  onSwipeMove(event: SwipeEvent) {
    console.log(`swipe direction: ${event.direction}`);
    console.log(`swipe distance: ${event.distance}`);
  }
  onSwipeEnd(event: SwipeEvent) {
    console.log(`swipe direction: ${event.direction}`);
    console.log(`swipe distance: ${event.distance}`);
  }  
}

Swipe direction

All four swipe directions(right, left, up, down) can be easily detected by filtering events by direction and distance fields in consumer component e.g. right swipe will have direction === 'x' and distance > 0.

Keywords

FAQs

Last updated on 05 Aug 2019

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