0

I'm using angular's ng-swipe-left and ng-swipe-right to catch swipe event (in touch). I'm trying to make an image rotate according to the swipe speed and diraction while swipe is in progress. The problem is that I'm able to catch the event only when the swipe end.

nameless
  • 1,483
  • 5
  • 32
  • 78
nufar
  • 77
  • 2
  • 8
  • Have a look at [this question](http://stackoverflow.com/questions/14432799/how-to-use-hammer-js-with-angular-js) and get familiar with "gestures" in angular. – Andre Kreienbring Oct 14 '15 at 14:37

1 Answers1

2

You have to listen to the start event. It is called on either mousedown or touchstar. But your problem is that: After the start event, $swipe is watching for touchmove or mousemove events that still ignored until the total distance moved in either dimension exceeds a small threshold.

Once this threshold is exceeded, the move event is created.

So you have to add a listener on the move event, wath is not possible with only Angularjs.

I think you have to use somethig with JQuery like this:

$('#someElm').bind('touchmove',function(e){
      e.preventDefault();
      var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
      var elm = $(this).offset();
      var x = touch.pageX - elm.left;
      var y = touch.pageY - elm.top;
      if(x < $(this).width() && x > 0){
          if(y < $(this).height() && y > 0){
                  //CODE GOES HERE
                  console.log(touch.pageY+' '+touch.pageX);
          }
      }
});

Angular documentation on this issue: AngularJS API : $swipe

Kacem
  • 79
  • 7