Ng 触摸鼠标向上不适用



我这里有一个标签:

https://plnkr.co/edit/EKpqNwQEHHHiFoiv43s3

我在手机或平板电脑上遇到了一个问题,我的ng-touch在鼠标向下而不是在鼠标向上发射,导致递增到无限,这是不希望的。

代码:

$scope.mouseDown = function(dir) { //this function fires when I press down on a phone
    promise = $interval(function() {
      if (dir === "up")
        $scope.quantity++;
      else
        $scope.quantity--;
    }, 100);
  };
  $scope.mouseUp = function() { //this function doesn't seem to fire when I stop the press on a phone
    $interval.cancel(promise);
  };

mouseup在触摸设备上不开火。不幸的是,ngTouch没有给你绑定触摸事件的指令。您需要抓取一个自定义指令,允许您绑定touchstarttouchend事件。有一些人在那里。我创建了一个要点,我写了一个在我的几个项目中很有效的要点:

https://gist.github.com/Toddses/fdd862648e10530038550e253212d9c1

这样,您就可以像绑定ng-mousedownng-mouseup一样在标记中绑定flux-touchstartflux-touchend

最新更新