An Ion (reusable Ionic widget) for adding tinder-style swipe cards to your app.
Created
November 17, 2015 18:43
-
-
Save pankajpatel/dde4d0b9845c87968757 to your computer and use it in GitHub Desktop.
Ionic Ion: Tinder Cards
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> | |
<link rel="stylesheet" href="http://code.ionicframework.com/contrib/ionic-contrib-tinder-cards/ionic.tdcards.css"> | |
<title>Ionic Swipe Down</title> | |
<link href="//code.ionicframework.com/1.0.0-beta.14/css/ionic.css" rel="stylesheet"> | |
<script src="http://code.ionicframework.com/collide/0.0.4/collide.js"></script> | |
<script src="//code.ionicframework.com/1.0.0-beta.14/js/ionic.bundle.js"></script> | |
<script src="http://code.ionicframework.com/contrib/ionic-contrib-tinder-cards/ionic.tdcards.js"></script> | |
</head> | |
<body ng-app="starter" no-scroll> | |
<ion-pane ng-controller="CardsCtrl"> | |
<ion-header-bar class="bar-default"> | |
<h1 class="title">TD Cards</h1> | |
</ion-header-bar> | |
<td-cards> | |
<td-card ng-repeat="card in cards" on-destroy="cardDestroyed($index)" on-swipe-left="cardSwipedLeft($index)" on-swipe-right="cardSwipedRight($index)" on-partial-swipe="cardPartialSwipe(amt)" class="card-{{$index}}"> | |
<div class="image" ng-controller="CardCtrl"> | |
<div class="no-text">NOPE</div> | |
<img ng-src="{{card.image}}"> | |
<div class="yes-text">LIKE</div> | |
</div> | |
</td-card> | |
</td-cards> | |
</ion-pane> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ionic Starter App, v0.9.20 | |
// angular.module is a global place for creating, registering and retrieving Angular modules | |
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html) | |
// the 2nd parameter is an array of 'requires' | |
// 'starter.services' is found in services.js | |
// 'starter.controllers' is found in controllers.js | |
angular.module('starter', ['ionic', 'ionic.contrib.ui.tinderCards']) | |
.config(function($stateProvider, $urlRouterProvider) { | |
}) | |
.directive('noScroll', function($document) { | |
return { | |
restrict: 'A', | |
link: function($scope, $element, $attr) { | |
$document.on('touchmove', function(e) { | |
e.preventDefault(); | |
}); | |
} | |
} | |
}) | |
.controller('CardsCtrl', function($scope, TDCardDelegate) { | |
console.log('CARDS CTRL'); | |
var cardTypes = [ | |
{ image: 'https://pbs.twimg.com/profile_images/546942133496995840/k7JAxvgq.jpeg' }, | |
{ image: 'https://pbs.twimg.com/profile_images/514549811765211136/9SgAuHeY.png' }, | |
{ image: 'https://pbs.twimg.com/profile_images/491995398135767040/ie2Z_V6e.jpeg' }, | |
]; | |
$scope.cards = Array.prototype.slice.call(cardTypes, 0); | |
$scope.cardDestroyed = function(index) { | |
$scope.cards.splice(index, 1); | |
}; | |
$scope.addCard = function() { | |
var newCard = cardTypes[Math.floor(Math.random() * cardTypes.length)]; | |
newCard.id = Math.random(); | |
$scope.cards.push(angular.extend({}, newCard)); | |
} | |
}) | |
.controller('CardCtrl', function($scope, TDCardDelegate) { | |
$scope.cardSwipedLeft = function(index) { | |
console.log('LEFT SWIPE'); | |
$scope.addCard(); | |
}; | |
$scope.cardSwipedRight = function(index) { | |
console.log('RIGHT SWIPE'); | |
$scope.addCard(); | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
td-cards { | |
display: block; | |
} | |
td-card { | |
position: absolute; | |
left: 50%; | |
margin-top: 80px; | |
margin-bottom: 40px; | |
margin-left: -150px; | |
width: 300px; | |
height: 300px; | |
border: 1px solid #999; | |
box-shadow: 0px 1px 3px rgba(0,0,0,0.2); | |
border-radius: 6px; | |
} | |
/* | |
td-card.card-0 { | |
-webkit-transform: translate3d(0, 0px, 0); | |
transform: translate3d(0, 0px, 0); | |
top: 0px; | |
z-index: 10; | |
} | |
td-card.card-1 { | |
-webkit-transform: translate3d(0, 4px, 0); | |
transform: translate3d(0, 4px, 0); | |
z-index: 9; | |
} | |
td-card.card-2 { | |
-webkit-transform: translate3d(0, 8px, 0); | |
transform: translate3d(0, 8px, 0); | |
z-index: 8; | |
} | |
*/ | |
td-card .image { | |
position: relative; | |
} | |
td-card img { | |
max-width: 100%; | |
border-radius: 6px; | |
} | |
.yes-text { | |
position: absolute; | |
top: 10px; | |
left: 10px; | |
font-size: 30px; | |
color: rgb(111, 250, 111); | |
opacity: 0; | |
} | |
.no-text { | |
position: absolute; | |
top: 10px; | |
right: 10px; | |
font-size: 30px; | |
color: rgb(255, 115, 115); | |
opacity: 0; | |
} | |
.fade { | |
-webkit-transition: 0.2s opacity linear; | |
transition: 0.2s opacity linear; | |
opacity: 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment