捏后阻止拖拽事件

时间:2016-11-22 08:28:03

标签: javascript angularjs ionic-framework

如何阻止$ionicGesture事件'拖动'在' pinchin'之后或者' pinchout'?

我已尝试e.preventDefault()e.gesture.preventDefault(),但仍会触发拖动事件。

$ionicGesture.on("drag", function (e) {
    cursor_gesture = e.gesture;
    cursor_center = cursor_gesture.center;
    _drag_to_edit();
}, photo);
$ionicGesture.on("pinchin", function (e) {
    console.log(e);
    e.preventDefault();
}, photo);
$ionicGesture.on("pinchout", function (e) {
    console.log(e);
    .preventDefault();
}, photo);

2 个答案:

答案 0 :(得分:0)

你也可以试试这些:

    event.preventDefault();
    event.stopPropagation();
    event.gesture.stopPropagation();
    event.gesture.preventDefault();
    event.gesture.stopDetect();

答案 1 :(得分:0)

在给定的时间内手动阻止其他事件处理程序:

var lastPinchTime = undefined;
var dragBlockTimeAmmount = 1000; //1 second
$ionicGesture.on("drag", function (e) {
  if( (new Date() - lastPinchTime) < dragBlockTimeAmmount){
    e.preventDefault();
  }
  else {
   // ...
   // your code here
   // ...
  }

}, photo);
$ionicGesture.on("pinchin", function (e) {
    lastPinchTime = new Date();
}, photo);
$ionicGesture.on("pinchout", function (e) {
    lastPinchTime = new Date();
}, photo);