Vì vậy, tôi đã thử cách này để làm việc với nhiều mục trên mỗi hoạt ảnh. Tôi cũng đã cố gắng áp dụng [Phát hiện cho trang web đáp ứng bằng AngularJS]. 2
Hãy xem ở đây: http://plnkr.co/edit/QhBQpG2nCAnfsb9mpTvj?p=preview
Kết quả:
1) Một mục (Mobile Version):
2) Hai Items (Tablet Phiên bản):
3) Ba Items (Phiên bản Desktop):
PHẦN 2: Nó cũng có thể phát hiện các nghị quyết của cửa sổ để xác định xem nó là tablet,mobile
hoặc desktop
sau tutorial ... Hãy thử sử dụng giá trị này: "mobile, tablet, desktop"
để xem ba giá trị khác nhau ent xem phiên bản.
trình diễn củatablet version
:
var app = angular.module('myApp', ['ui.bootstrap', 'angular-responsive']);
app.controller('MainCtrl', function($scope) {
$scope.displayMode = 'mobile'; // default value
$scope.$watch('displayMode', function(value) {
switch (value) {
case 'mobile':
// do stuff for mobile mode
console.log(value);
break;
case 'tablet':
// do stuff for tablet mode
console.log(value);
break;
}
});
});
function CarouselDemoCtrl($scope) {
var whatDevice = $scope.nowDevice;
$scope.myInterval = 7000;
$scope.slides = [{
image: 'http://placekitten.com/221/200',
text: 'Kitten.'
}, {
image: 'http://placekitten.com/241/200',
text: 'Kitty!'
}, {
image: 'http://placekitten.com/223/200',
text: 'Cat.'
}, {
image: 'http://placekitten.com/224/200',
text: 'Feline!'
}, {
image: 'http://placekitten.com/225/200',
text: 'Cat.'
}, {
image: 'http://placekitten.com/226/200',
text: 'Feline!'
}, {
image: 'http://placekitten.com/227/200',
text: 'Cat.'
}, {
image: 'http://placekitten.com/228/200',
text: 'Feline!'
}, {
image: 'http://placekitten.com/229/200',
text: 'Cat.'
}, {
image: 'http://placekitten.com/230/200',
text: 'Feline!'
}];
var i, first = [],
second, third;
var many = 1;
//##################################################
//Need to be changed to update the carousel since the resolution changed
$scope.displayMode = "tablet";
//##################################################
if ($scope.displayMode == "mobile") {many = 1;}
else if ($scope.displayMode == "tablet") {many = 2;}
else {many = 3;}
for (i = 0; i < $scope.slides.length; i += many) {
second = {
image1: $scope.slides[i]
};
if (many == 1) {}
if ($scope.slides[i + 1] && (many == 2 || many == 3)) {
second.image2 = $scope.slides[i + 1];
}
if ($scope.slides[i + (many - 1)] && many == 3) {
second.image3 = $scope.slides[i + 2];
}
first.push(second);
}
$scope.groupedSlides = first;
}
app.directive('dnDisplayMode', function($window) {
return {
restrict: 'A',
scope: {
dnDisplayMode: '='
},
template: '<span class="mobile"></span><span class="tablet"></span><span class="tablet-landscape"></span><span class="desktop"></span>',
link: function(scope, elem, attrs) {
var markers = elem.find('span');
function isVisible(element) {
return element && element.style.display != 'none' && element.offsetWidth && element.offsetHeight;
}
function update() {
angular.forEach(markers, function(element) {
if (isVisible(element)) {
scope.dnDisplayMode = element.className;
return false;
}
});
}
var t;
angular.element($window).bind('resize', function() {
clearTimeout(t);
t = setTimeout(function() {
update();
scope.$apply();
}, 300);
});
update();
}
};
});
Hy vọng nó sẽ giúp!
[Tôi có nên sử dụng băng chuyền không?] (Http://www.shouldiuseacarousel.com/) (Spoiler: câu trả lời là không). Là một băng chuyền thực sự, thực sự cần thiết? – GregL
@GregL Xin chào Greg, vâng tôi đã đọc điều đó trước và không may là yêu cầu của nó từ doanh nghiệp và đã được các nhà phát triển đặt câu hỏi - họ đang gắn bó với nó – Katana24
Bạn có thể xem https://github.com/ gilbitron/carouFredSel. Đó là một băng chuyền đáp ứng (được xây dựng trên đầu trang của jQuery) – HerrSerker