Maus-events auf touch-Fall für ipad Kompatibilität

habe ich diese Kinder malen app, die Maus-events verwendet, um Farbe auf ein Bild. Allerdings muss ich konvertieren Maus-Ereignisse zu berühren, so dass es könnte die Arbeit an einem ipad. Bitte kann jemand mir erklären, wie dies zu tun. Meine app-code ist ganz ähnlich wie dieses Beispiel-code http://cool-php-tutorials.blogspot.co.uk/2011/05/simple-html5-drawing-app-with-saving.html.

P. S meine Kenntnisse über javascript ist nicht auf ein advanced level also bitte, wenn Sie mir zeigen, arbeiten oder code-Beispiele werden eine große Hilfe

Mein code, funktioniert die Maus-event sind wie folgt. Bitte können verdeckte diese Funktionalität von Maus zu berühren.. bitte, ich bin stecken geblieben auf diese seit 2 Tagen jetzt.. 😐

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();
  }
}

InformationsquelleAutor Ash | 2013-07-12

Schreibe einen Kommentar