Я начал изучать холст и столкнулся с проблемой: рисовать с помощью холста с помощью мыши, включенной с помощью мыши, перемещения мышью, работы с мышью, и для сенсорной панели iPad использовал touchstart, touchmove, touchend, однако код для сенсорной панели не работает,Я закомментировал нерабочий код, буду благодарен за помощь и руководство по правильному пути.
Код для рисования canvas в ipad не работает canvas.ontouchstart, canvas.touchstart, canvas.touchmove, canvas.touchend
function unit(){
canvasOffset = canvas.getBoundingClientRect();
ctx.lineJoin = "round";
canvas.onmousedown = function(e) {
drawing = true;
ctx.beginPath();
}
//canvas.ontouchstart = function(e) {
// if (e.touches) e = e.touches[0];
// return false;
//}
//canvas.touchstart = function(e) {
// drawing = true;
// ctx.beginPath();
//}
canvas.onmousemove = function(e) {
if (drawing) {
var mousePosition = getMousePosition(e);
ctx.lineTo(mousePosition[0], mousePosition[1]);
myColor = document.getElementById('myColor').style.background;
ctx.strokeStyle = myColor;
ctx.stroke();
}
};
//canvas.touchmove = function(e) {
// if (drawing) {
// var mousePosition = getMousePosition(e);
// ctx.lineTo(mousePosition[0], mousePosition[1]);
// myColor = document.getElementById('myColor').style.background;
// ctx.strokeStyle = myColor;
// ctx.stroke();
// }
//};
canvas.onmouseup = function(e) {
drawing = false;
ctx.closePath();
}
//canvas.touchend = function(e) {
// drawing = false;
// ctx.closePath();
//}
function getMousePosition(mouseEvent) {
return [Math.floor(event.offsetX), Math.floor(event.offsetY)];
}
}