【发布时间】:2019-01-18 12:44:41
【问题描述】:
我在尝试使用 AngularJS 加载猫头鹰轮播时遇到了一个奇怪的问题。
我使用以下 ng-repeat 创建所有幻灯片:
<div class="owl-carousel owl-theme" id="newsCarousel" banner-container>
<img class="img-fluid" ng-src="{{banner.URL}}"
ng-repeat="banner in vm.banners" banner-card>
</div>
然后用这些指令初始化轮播:
app.directive('bannerCard', function ($timeout){
return function(scope, element, attrs){
if(scope.$last)
return $timeout(function(){
scope.$emit('LastBannerRendered');
});
};
});
app.directive('bannerContainer', function ($timeout){
return function(scope, element, attrs){
$timeout(function(){
scope.$on('LastBannerRendered', function(event){
$('#newsCarousel').owlCarousel({
autoplay: true,
loop:true,
autoplayTimeout: 5000,
items: 1,
nav: true,
dots: false,
navText : ["<i class='fa fa-chevron-left'></i>","<i class='fa fa-chevron-right'></i>"]
});
});
});
}
});
到目前为止,我已经多次执行此操作(同一页面中还有 2 个其他轮播像这样完成并且工作 100% 正常)但是这个特定的轮播似乎无法正常工作,问题是在初始化时幻灯片的高度超过 2000 像素,这是一个破坏整体视图的惊人数量。
当我通过控制台初始化轮播时,它不会变得过大,但它没有溢出:隐藏,因此所有幻灯片都一个接一个地显示。
我在这里遗漏了什么导致这个特定的轮播呈现这样的行为?
添加更多细节:图像最初以正确的大小加载,我可以看到它们大约一秒钟,然后应用了一些样式,使它们具有这个大小。
【问题讨论】:
-
您是否按照AngularJS documentation 的建议在
angular.js之前加载了jquery.js? -
@georgeawg 很抱歉延迟回复,但我是。
标签: javascript jquery css angularjs owl-carousel