マウスイベントを使用して画像にペイントするこの子供用ペイントアプリがあります。ただし、iPadで動作するように、マウスイベントをタッチに変換する必要があります。誰かがこれを行う方法を説明してください。私のアプリ コードは、このサンプル コードhttp://cool-php-tutorials.blogspot.co.uk/2011/05/simple-html5-drawing-app-with-saving.htmlとよく似ています。
PS 私の javascript に関する知識は高度なレベルではないので、実際のコードや例を見せていただければ大変助かります。
マウスイベントを行う私のコードは次のとおりです。この機能をマウスからタッチに変換してください..お願いします.2日以来、これで立ち往生しています..:|
var clickX = new Array();
var clickY = new Array();
var clickDrag = new Array();
// binding events to the canvas
$('#drawingCanvas').mousedown(function(e){
var mouseX = e.pageX - this.offsetLeft;
var mouseY = e.pageY - this.offsetTop;
paint = true; // start painting
addClick(e.pageX - this.offsetLeft, e.pageY - this.offsetTop);
// always call redraw
redraw();
});
$('#drawingCanvas').mousemove(function(e){
if(paint){
addClick(e.pageX - this.offsetLeft, e.pageY - this.offsetTop, true);
redraw();
}
});
// when mouse is released, stop painting, clear the arrays with dots
$('#drawingCanvas').mouseup(function(e){
paint = false;
clickX = new Array();
clickY = new Array();
clickDrag = new Array();
});
// stop painting when dragged out of the canvas
$('#drawARobot').mouseleave(function(e){
paint = false;
});
// The function pushes to the three dot arrays
function addClick(x, y, dragging)
{
clickX.push(x);
clickY.push(y);
clickDrag.push(dragging);
}
// this is where actual drawing happens
// we add dots to the canvas
function redraw(){
for(var i=0; i < clickX.length; i++)
{
context.beginPath();
if(clickDrag[i] && i){
context.moveTo(clickX[i-1], clickY[i-1]);
}else{
context.moveTo(clickX[i]-1, clickY[i]);
}
context.lineTo(clickX[i], clickY[i]);
context.closePath();
context.stroke();
}
}