【问题标题】:using the $swipe Service in angular-touch在 angular-touch 中使用 $swipe 服务
【发布时间】:2015-12-02 05:08:34
【问题描述】:

我正在尝试使用 angular-touch 模块及其 $swipe 服务以及 html5 画布制作一个基本的绘图程序,这是我想出的,它包含在我知道有效的模块和控制器中

this.canvas=angular.element('canvas')[0];
console.log(this.canvas.on)
this.canvasCord=angular.element(this.canvas).offset();
var ctx=this.canvas.getContext('2d');
$swipe.bind(angular.element('canvas'),{start:this.startDraw,move:this.coninueDraw,end:this.continueDraw,cancel:function(event){console.log(event);}},["mouse","touch"]);
var convertCord=function(cord){
    cord.x=cord.x-this.canvasCord.left;
    cord.y=cord.y-this.canvasCord.top;
    return cord;
};
this.startDraw=function(cord,event){
    console.log('starting')
    cord=convertCord(cord);
    ctx.beginPath()
    ctx.moveTo(cord.x,cord.y);
    ctx.lineWidth='5';
};
this.continueDraw=function(cord,event){
    console.log(cord);
    cord=convertCord(cord);
    ctx.lineTo(cord.x,cord.y);
    ctx.stroke();
};

我的画布的 html 只是一个基本的<canvas></canvas>

我的问题是,当元素被触摸、点击或滑动时,作为$swipe.bind() 一部分的事件函数从未真正被调用。我似乎可以开始工作的唯一回调是我在短时间内重复点击或单击画布的取消。我正在使用 jquery mobile,但在 jquery 和 jquery mobile 之后加载 angularjs 和 angularjs-touch。有谁知道为什么这不起作用?

【问题讨论】:

    标签: javascript jquery angularjs angular-touch


    【解决方案1】:

    我发现我的问题是对this 对象的引用,这在$swipe 中的定义不同,将它们转换为普通变量,而不是将它们附加到修复它的对象上。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-13
      • 2013-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-11
      相关资源
      最近更新 更多