请为我的旋转木马使用猫头鹰旋转木马。我的旋转木马非常类似于http://thebootstrapthemes.com/live/thebootstrapthemes-zenclassified/。我遇到了类似的解决方案Here和此处。然后我在下面的控制器中添加了一个类似的指令。
.directive('owlCarousel', function(){
return {
restrict: 'E',
transclude: false,
link: function (scope) {
scope.initCarousel = function(element) {
// provide any default options you want
var defaultOptions = {
autoplay:true,
autoplayTimeout:2500,
loop:false,nav : true,
responsiveClass:true,
margin: 30,
responsive:{
0:{items:1},
767:{items:3},
992:{items:4}
}
};
var customOptions = scope.$eval($(element).attr('data-options'));
// combine the two options objects
for(var key in customOptions) {
defaultOptions[key] = customOptions[key];
}
// init carousel
$(element).owlCarousel(defaultOptions);
};
}
};
}).directive('owlCarouselItem', [function() {
return {
restrict: 'A',
transclude: false,
link: function(scope, element) {
// wait for the last item in the ng-repeat then call init
if(scope.$last) {
scope.initCarousel(element.parent());
}
}
};
}]);
上述作品除外。最后一项的高度增加超出下面的其他项目。
您可以看到上面显示的最后一项。请问我该如何解决这个问题,原因是什么?任何帮助将不胜感激。
答案 0 :(得分:2)
试试这个
.directive('owlCarousel', function(){
return {
restrict: 'EA',
transclude: false,
link: function (scope, element, attrs) {
scope.initCarousel = function() {
// provide any default options you want
var defaultOptions = {
autoplay:true,
autoplayTimeout:2500,
loop:false,nav : true,
responsiveClass:true,
margin: 30,
responsive:{
0:{items:1},
767:{items:3},
992:{items:4}
}
};
$(element).owlCarousel(defaultOptions);
};
}
};
}).directive('owlCarouselItem',[function() {
return function(scope) {
if (scope.$last) {
scope.initCarousel();
}
};
}]);
请参阅此问题。这对我有用。