joeybab3
joeybab3

Reputation: 317

javascript canvas touchstart and touchend not working on touchscreen

Using the phpacademy painting app tutorial, I attempted to add touchscreen support.I have the same code for mouse and touch, however touchup and down are not triggered.

canvas.addEventListener('mousedown', engage);
canvas.addEventListener('mousemove', putPoint);
canvas.addEventListener('touchstart', engage);
canvas.addEventListener('touchmove', putPoint);
canvas.addEventListener('mouseup', disengage);
canvas.addEventListener('mouseout', disengage);
canvas.addEventListener('touchend', disengage);

Upvotes: 1

Views: 3128

Answers (1)

Zach Babb
Zach Babb

Reputation: 668

The canvas element doesn't receive the touchstart events (lame I know). In order to get it to work you'll have to hack something up like absolute position a div over the canvas and use the div to catch the touchstart event.

Upvotes: 2

Related Questions