【发布时间】:2019-08-21 18:54:51
【问题描述】:
我正在开发一个使用 HTML、CSS 和 JS 的刷卡项目。
我从 codepen 获取了这个 JS 代码并实现了它,但问题是卡片是随机的。如何使其按顺序排列(不重复)?
angular.module('starter', ['ionic', 'ionic.contrib.ui.cards'])
.directive('noScroll', function($document) {
return {
restrict: 'A',
link: function($scope, $element, $attr) {
$document.on('touchmove', function(e) {
e.preventDefault();
});
}
}
})
.controller('CardsCtrl', function($scope, $ionicSwipeCardDelegate) {
var cardTypes = [
{title: '1'},
{title: '2'},
{title: '3'},
{title: '4'},
{title: '5'}
];
$scope.cards = Array.prototype.slice.call(cardTypes, 0, 0);
$scope.cardSwiped = function(index) {
$scope.addCard();
};
$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, $ionicSwipeCardDelegate) {
$scope.goAway = function() {
var card = $ionicSwipeCardDelegate.getSwipeableCard($scope);
card.swipe();
};
});
【问题讨论】:
标签: javascript jquery html css angularjs