Angular-Touch库用法示例
更新时间:2016年12月22日 14:31:54 作者:wheatmark
这篇文章主要介绍了Angular-Touch库用法,结合触屏滑动事件的实现为例分析了Angular-Touch库的相关使用技巧,需要的朋友可以参考下
本文实例讲述了Angular-Touch库用法。分享给大家供大家参考,具体如下:
Angular-touch库用的不多,网上的例子也不多。写个触屏滑动的事件。
先在页面上弄个div
1 2 3 4 5 | < div id = "content" align = "center" ng-app = "imageApp" image-controller = "" > < p style = "position: absolute; width: 100%; margin-top: 30px;z-index: -1;" > < img id = "show" src = "assets/image/logo.jpg" /> </ p > </ div > |
引入两个库
1 2 | <script type= "text/javascript" src= "js/angular/1.4.6/angular.min.js" ></script> <script type= "text/javascript" src= "js/angular/1.4.6/angular-touch.min.js" ></script> |
注册事件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | try { angular.module( 'imageApp' ,[ 'ngTouch' ]) .directive( 'imageController' ,[ '$swipe' , function ($swipe){ return { restrict: 'EA' , link: function (scope,ele,attrs,ctrl){ var startX,startY,locked= false ; $swipe.bind(ele,{ 'start' : function (coords){ startX = coords.x; startY = coords.y; }, 'move' : function (coords){ var delta = coords.x - startX; if (delta<-300 && !locked){ console.log( 'trun right' ); } else if (delta>300 && !locked){ console.log( 'trun left' ); } }, 'end' : function (coords){ }, 'cancel' : function (coords){ } }); } } } ]); } catch (e){ console.error(e); } |
更多关于AngularJS相关内容感兴趣的读者可查看本站专题:《AngularJS入门与进阶教程》及《AngularJS MVC架构总结》
希望本文所述对大家AngularJS程序设计有所帮助。