Sketch.js pageX未定义错误 [英] Sketch.js pageX undefined error
问题描述
我在我的phonegap应用程序中使用通过intridea的sketch.js。它可以直接修改
I am using sketch.js by intridea in my phonegap application.It works allright with the modification
case 'touchstart':
if (this.painting) {//add
this.stopPainting();
//add
}//add
this.startPainting();
break;
通过将以上行添加到代码。但我得到一个pageX未定义的错误,这是崩溃我的app。
by adding the above lines to the code.But I am getting a pageX undefined error which is crashing my app.
01-23 19:53:59.342: E/Web Console(31932): Uncaught TypeError: Cannot read property 'pageX' of undefined at file:///android_asset/www/js/external_libs/sketch.js:107
如何克服这个问题,任何帮助将不胜感激。
How to overcome this issue,any help would be appreciated.Thanks
推荐答案
似乎每个人都swfhed到jqscribbel .js,但是要直接用sketch.js回答这个问题,你需要检查是否定义了 e.originalEvent.targetTouches [0]
。我还没有挖掘sketch.js太多,但似乎当触发事件被触发, e.originalEvent.targetTouches [0]
不再定义,因此试图找到 .pageX
of undefined会出错。此错误导致整个画布被重新绘制,因此您无法在画布上绘制超过1个草图。要修复此错误,只需添加以下两行代码(在第100/101行附近):
It seems as if everyone has swtiched over to jqscribbel.js, but to directly answer this question with sketch.js, you need to check if e.originalEvent.targetTouches[0]
is defined. I haven't dug into sketch.js too much yet, but it seems that when a touchup event is triggered, e.originalEvent.targetTouches[0]
is no longer defined, so trying to find .pageX
of undefined gives an error. This error causes the entire canvas to be re-drawn, so you cannot draw more than 1 sketch on the canvas. To fix this error, simply add find the following two lines of code (around line 100/101):
e.pageX = e.originalEvent.targetTouches[0].pageX;
e.pageY = e.originalEvent.targetTouches[0].pageY;
并替换为
if (e.originalEvent.targetTouches[0] !== undefined && e.originalEvent.targetTouches[0].pageX !== undefined){
e.pageX = e.originalEvent.targetTouches[0].pageX;
}
if (e.originalEvent.targetTouches[0] !== undefined && e.originalEvent.targetTouches[0].pageY !==undefined){
e.pageY = e.originalEvent.targetTouches[0].pageY;
}
这篇关于Sketch.js pageX未定义错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!