jQuery Carousel with Angular ng-repeat
来源:互联网 发布:android 网络加载提示 编辑:程序博客网 时间:2024/05/17 02:05
jQuery Carousel with Angular ng-repeat
问题: 在使用ng-repeat循环加载一组图片时,carousel图片轮播插件失效
原因 : jquery 获取DOM元素需要在ng-repeat循环加载渲染结束后进行。参考内容
解决方法1 : 利用directive实现, 指令可以重用
- add directive
angular.module('myApp', []).directive('owlCarousel', function () { return { restrict: 'E',//作用于每一个元素 link: function (scope, element, attrs) { var options = scope.$eval($(element).attr('data-options'));//获取data-options属性值 $(element).owlCarousel(options);//初始化owlCarousel插件 } };});
2.. 在HTML中使用新标签
<owl-carousel class="owl-carousel" data-options="{autoPlay: 5000, stopOnHover: true,slideSpeed : 300, paginationSpeed : 400, singleItem : true}"> //设置图片轮播属性 <ul><li ng-repeat="pic in pics"> <img src="{{pic.url}}"/> </li></ul></owl-carousel>
解决方法2 : 利用ng-init快速实现,无法重用 [参考]
<ul id="owl-example"><li ng-repeat="pic in pics" ng-init="$last ? initOwlCarousel() : null"> <img src="{{pic.url}}"/></li></ul>
$scope.pics = ['a.jpg', 'b.jpg', 'c.jpg'];$scope.initOwlCarousel = function(){ $(document).ready(function(){ var options = "{autoPlay: 5000, stopOnHover: true,slideSpeed : 300, paginationSpeed : 400, singleItem : true}" ; $("#owl-example").owlCarousel(options); });}
备注
scope.$eval
,是执行当前作用域下的表达式,如:scope.$eval('a+b');
而这个里的a,b是来自scope = {a: 2, b:3};
- owl carousel 插件官网: http://owlgraphic.com/owlcarousel/
0 0
- jQuery Carousel with Angular ng-repeat
- angular ng-repeat嵌套
- Angular Js ng-repeat指令
- angular select ng-options和ng-repeat
- Angular——迭代器ng-repeat
- Angular ng-repeat 不识别json问题
- angular学习日志07 ng-repeat
- angular用ng-repeat批量处理数据
- Angular的ng-repeat的技巧
- angular ng-repeat set last element style
- Angular - ng-repeat 一些高级用法
- Angular之ng-repeat批量生产组件
- angular用ng-repeat遍历对象
- angular中ng-repeat及track by
- 【Angular】ng-repeat遍历输出数组
- angular指令监听ng-repeat渲染完成
- angular中filter查询与ng-repeat
- angular中的ng-repeat-start和ng-repeat-end的用法介绍
- 美团外卖订单中心的演进
- 关于A*算法的一些研究
- iOS开发 适配Xcode8以及iOS10-权限问题
- django-2:django开发初探
- UINavigationBar
- jQuery Carousel with Angular ng-repeat
- 判断(img标签)中src的路径中照片文件是否存在
- Ubuntu下ZooKeeper安装过程
- 处理触屏消息
- 项目开发过程一些注意事项
- 洛谷 P1182 数列分段Section II
- android5.0以上手机host修改教程
- C#调用C++ DLL
- MaterialDesign 的三方控件