加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular-Touch库使用

发布时间:2020-12-17 10:11:21 所属栏目:安全 来源:网络整理
导读:Angular-touch库用的不多,网上的例子也不多。写个触屏滑动的事件。 先在页面上弄个div div id = "content" align = "center" ng-app = "imageApp" image-controller = "" p style = "position: absolute; width: 100%; margin-top: 30px;z-index: -1;" img

Angular-touch库用的不多,网上的例子也不多。写个触屏滑动的事件。

先在页面上弄个div

<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>

引入两个库

<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>

注册事件

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);
        }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读