mobomo / sketch.js

A jQuery plugin for dead simple Canvas-based drawing.
http://intridea.github.com/sketch.js
290 stars 110 forks source link

touchTargets undefined on touchend/touchleave #22

Open x68507 opened 10 years ago

x68507 commented 10 years ago

When drawing on a canvas on a mobile device, there is an error "Uncaught TypeError: Cannot read property 'pageX' of undefined" on the touchend/touchleave bound to the canvas. The script is trying to call "e.originalEvent.targetTouches[0].pageX;", but it appears that on the touchend/touchleave event, "e.originalEvent.targetTouches[0]" is not defined, causing an error and resetting the entire canvas on mobile. You can simply encase the .pageX and .pageY lines in an if statement checking if both .targetTouches[0] and .targetTouche[0].pageX are defined. See any below:

http://stackoverflow.com/questions/21311073/sketch-js-pagex-undefined-error/22976319#22976319

Rudloff commented 10 years ago

This can be easily fixed like this: https://gist.github.com/Rudloff/cdc38001248b5f35551f

lenichols commented 8 years ago

This fix worked for me...