移动屏幕按下按钮时保持旋转

时间:2014-11-20 09:21:58

标签: javascript jquery html mobile mobile-browser

请参阅http://liveweave.com/0POip0

我希望当用户保持"旋转"文本按下组对象继续旋转?  一旦用户移除触摸按停止旋转

$('#rotate').on({
    'mousedown touchstart click': function () {
         var x=setInterval(function () {group.setAngle(group.getAngle()+30);canvas.renderAll();}, 3000);
        return false;
    },
    'mouseup touchend': function () {
      clearInterval(x);
    }
});

收到错误未捕获的ReferenceError:x未定义

2 个答案:

答案 0 :(得分:0)

$('#rotate').on({
    'mousedown touchstart click': function () {
        var x=setInterval(function () {group.setAngle(group.getAngle()+30);canvas.renderAll();}, 3000);
        return false;
    },
    'mouseup touchend': function () {
        clearInterval(x);``
    }
});

答案 1 :(得分:0)

解决需要初始化var x的值

var x=null;
$('#rotate').on({
    'mousedown touchstart click': function () {
         var x=setInterval(function () {group.setAngle(group.getAngle()+30);canvas.renderAll();}, 3000);
        return false;
    },
    'mouseup touchend': function () {
      clearInterval(x);
    }
});