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

angular-swipe-element

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-swipe-element

Small extension for AngularJs to add wider support of swipe events on element.

  • 0.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

angular-swipe-element

Small extension for AngularJS to add wider support of swipes and drags

Live Demo here.

Basic usage

Define module as dependency!

var app = angular.module('app', ['angular-swipe-element']);

Define the directive!

<div swipe-element="onSwipeEnd(dir, deltaX, deltaY)" 
     swipe-element-move="onSwipeMove(dir, deltaX, deltaY)" 
     swipe-element-start="onSwipeStart(dir, deltaX, deltaY)"></div>

Define the callbacks in controller!

app.controller(function($scope) {
    $scope.onSwipeStart = function(dir, deltaX, deltaY) { console.log('Started, direction: ' + dir + '. DeltaX: ' + deltaX + '; DeltaY: ' + deltaY); };
    $scope.onSwipeMove = function(dir, deltaX, deltaY) { console.log('Moved, direction: ' + dir + '. DeltaX: ' + deltaX + '; DeltaY: ' + deltaY); };
    $scope.onSwipeEnd = function(dir, deltaX, deltaY) { console.log('Released, direction: ' + dir + '. DeltaX: ' + deltaX + '; DeltaY: ' + deltaY); };
});

You are ready! Enjoy the plugin.

Directive attributes

Directive can be used to catch swipe(mouse drag) start/move/end events. You can pass callbacks for these events in the following attributes:

AttributeRequiredDescription
swipe-elementRequiredFires when user stops swiping/dragging current element
swipe-element-startoptionalFires when user touches/mousedowns current element
swipe-element-moveoptionalFires when user moves finger/mouse while holding current element

Callback parameter

When some event is fired, directive callback's scopes are provided with $event parameter as well as with the following properties which could be used for your needs:

PropertyDescription
$eventContains all of the data properties
xCurrent X coordinate of the pointer in the document
yCurrent X coordinate of the pointer in the document
deltaXDifference on the X axis, comparing to swipe/drag starting point. (currentPosition - startingPosition)
deltaXDifference on the Y axis, comparing to swipe/drag starting point. (currentPosition - startingPosition)
dirString value representing direction, in which swipe/drag is heading. Can be equal to '', 'u', 'd', 'l', 'r'. If deltaX and deltaY equal to each other and not equal 0 takes horizontal value.
hDirString value representing direction, in which swipe/drag is heading on X axis. Can be equal to '', 'l', 'r'.
vDirString value representing direction, in which swipe/drag is heading on Y axis. Can be equal to '', 'u', 'd'.
startXX coordinate of the pointer in the document, when swipe/drag started
startYY coordinate of the pointer in the document, when swipe/drag started
initialElementBoundsgetClientBoundingRect() executed on element when the swipe/drag started.
triggerTypeCould be used to differ mouse and touch events. String value. Can be 'mouse' or 'touch'.
sourceSource DOM event.

License

MIT license.

Contribution

You are welcome to contribute. Feel free to contact me.

Keywords

FAQs

Package last updated on 26 Apr 2017

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