Home

Awesome

<!-- This file has been generated using GitDown (https://github.com/gajus/gitdown). Direct edits to this will be be overwritten. Look for GitDown markup file under ./.gitdown/ path. --> <h1 id="angular-swing">angular-swing</h1>

NPM version Bower version

AngularJS directive for Swing: A swipeable cards interface. The swipe-left/swipe-right for yes/no input. As seen in apps like Jelly and Tinder, and many others.

Give it a swing! and please tweet it if you like it. : )

Card stack example.

<h2 id="angular-swing-usage">Usage</h2>

Include ./dist/angular-swing.js..

Load gajus.swing module, e.g.

angular.module('your-module', ['gajus.swing']);

Loading gajus.swing module will make available the swing-stack and swing-card directives.

Prepare a Swing stack:

<ul swing-stack></ul>

Add a Card to the Swing stack:

<ul swing-stack>
    <li swing-card></li>
</ul>

Attach event listeners to the instance of Card:

<ul swing-stack>
    <li
        swing-card
        swing-on-throwout="console.log(eventName, eventObject)"
        swing-on-throwoutleft="console.log(eventName, eventObject)"
        swing-on-throwoutright="console.log(eventName, eventObject)"
        swing-on-throwin="console.log(eventName, eventObject)"
        swing-on-dragstart="console.log(eventName, eventObject)"
        swing-on-dragmove="console.log(eventName, eventObject)"
        swing-on-dragend="console.log(eventName, eventObject)"
        ></li>
</ul>

Use scope variable to change Swing Stack default options:

$scope.options = {
    throwOutConfidence: function (offset, element) {
        console.log('throwOutConfidence', offset, element.offsetWidth);
        return Math.min(Math.abs(offset) / element.offsetWidth, 1);
    },
    isThrowOut: function (offset, element, throwOutConfidence) {
        console.log('isThrowOut', offset, element.offsetWidth, throwOutConfidence);
        return throwOutConfidence === 1;
    }
};
<ul swing-stack swing-options="options">...</ul>

Use scope variables/methods to add/remove cards:

<ul swing-stack>
    <li
        swing-card
        swing-on-throwout="remove($index)"
        ng-repeat="card in cards"
        >{{card.name}}</li>
</ul>
$scope.cards = [
    {name: 'foo'},
    {name: 'bar'}
];
$scope.remove = function (index) {
    $scope.cards.splice(index, 1);
}
$scope.add = function (name) {
    $scope.cards.push({name: name});
};
<h3 id="angular-swing-usage-examples">Examples</h3>

There are more examples that using the standalone Swing.

The code for all of the examples is in the ./examples/ folder.

Raise an issue if you are missing an example.

<h2 id="angular-swing-events">Events</h2>

Swing Documentation for the Events.

Swing events translate to the following attributes in the AngularJS directive:

NameDescription
throwoutswing-on-throwout
throwoutleftswing-on-throwoutleft
throwoutrightswing-on-throwoutright
throwinswing-on-throwin
dragstartswing-on-dragstart
dragmoveswing-on-dragmove
dragendswing-on-dragend

Event listener expression can use eventName and eventObject parameters.

<h3 id="angular-swing-events-event-object">Event Object</h3>

Swing Documentation for the Event Object.

<h2 id="angular-swing-download">Download</h2>

Using Bower:

bower install angular-swing

Using NPM:

npm install angular-swing