$ionicGesture

ionic.EventController的手势中的关于手势的angular服务。

方法:

on(eventType, callback, $element)
  • 给某个元素增加手势监听时间。参看:ionic.EventController
  • 参数:eventType 类型:string 说明:监听的手势时间类型
  • 参数:callcallback 类型:function(e) 说明:手势触发后回调的函数
  • 参数:$element 类型:元素element 说明:监听时间的元素
  • 返回类型:ionic.Gesture 类型的对象,后面可以用这个对象移除监听的事件。
off(gesture, eventType, callback)
  • 移除元素监听的手势事件,参看:ionic.EventController
  • 参数:gesture 类型:ionic.Gesture 说明:要移除的手势对象(绑定手势时返回的对象)
  • 参数:eventType 类型:string 说明:移除的手势事件类型
  • 参数:callback 类型:function(e) 说明:移除手势后的回调函数

例子

在线demo

html:

<html ng-app="ionicApp">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <title>Ionic $ionicGesture example: 1.0.0-beta.14</title>

  <link href="http://code.ionicframework.com/1.0.0-beta.14/css/ionic.css" rel="stylesheet">
  <script src="http://code.ionicframework.com/1.0.0-beta.14/js/ionic.bundle.js">
  </script>
</head>

<body ng-controller="MyCtrl" class="padding">
  <div class="bar bar-header bar-positive">
    <h1 class="title"></h1>
  </div>
  <ion-content id="eventPlaceholder" has-bouncing="false"></ion-content>
</body>

</html>

css:

body {
  cursor: url('http://ionicframework.com/img/finger.png'), auto;
}

js:

angular.module('ionicApp', ['ionic'])

.controller('MyCtrl', function($scope, $ionicGesture, $window, $interval) {
  $scope.lastEventCalled = 'Try to Drag the content up, down, left or rigth';
  var element = angular.element(document.querySelector('#eventPlaceholder'));
  var events = [{
    event: 'dragup',
    text: 'You dragged me UP!'
  },{
    event: 'dragdown',
    text: 'You dragged me Down!'
  },{
    event: 'dragleft',
    text: 'You dragged me Left!'
  },{
    event: 'dragright',
    text: 'You dragged me Right!'
  }];

  angular.forEach(events, function(obj){
    $ionicGesture.on(obj.event, function (event) {
      $scope.$apply(function () {
        $scope.lastEventCalled = obj.text;
      });
    }, element);
  });
});