To fix this error, you need to change several different lines of code. The plugin checks during each event if the user uses the desktop (mousedown, mousemove, mouseleave, mouseup) or mobile (touchstart, touchhend, touchcancel). To determine the position of the mouse / finger to draw the next point, jQuery e.pageX . This is directly defined on the mobile phone, so the plugin checks for the presence of a mobile phone and detects the mobile connection, while maintaining the user's finger position determined by e.originalEvent.targetTouches[0].pageX . The problem arises from touchhend or touchcancel because e.originalEvent.targetTouches[0] not defined for these two events, therefore e.originalEvent.targetTouches[0].pageX returns an error and the entire canvas is redrawn. To fix this, you need to edit 2 lines of code around line 100/101.
Replace
e.pageX = e.originalEvent.targetTouches[0].pageX; e.pageY = e.originalEvent.targetTouches[0].pageY;
FROM
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){ e.pageY = e.originalEvent.targetTouches[0].pageY; }
See below for more details.
Sketch.js pageX undefined error
Michael
source share