Coordinate error in digital signature canvas

0

I find myself with a coordinate error in canvas, I think it is of coordinates since I place in the top of my 1 line of code and it works well

but I put it down and it does not let me draw this is my code

var canvas = document.getElementById('sketchpad');
  window.addEventListener('load',function(){

    canvas = document.getElementById('sketchpad');
    var context = canvas.getContext('2d');

    var drawer = {
      isDrawing: false,
      touchstart: function(coors){
        context.beginPath();
        context.moveTo(coors.x, coors.y);
        this.isDrawing = true;
      },
      touchmove: function(coors){
        if (this.isDrawing) {
              context.lineTo(coors.x, coors.y);
              context.stroke();
        }
      },
      touchend: function(coors){
        if (this.isDrawing) {
              this.touchmove(coors);
              this.isDrawing = false;
        }
      }
    };

    function draw(event){

      var coors = {
        x: event.targetTouches[0].pageX,
        y: event.targetTouches[0].pageY
      };

      drawer[event.type](coors);

    }

    // attach the touchstart, touchmove, touchend event listeners.
      canvas.addEventListener('touchstart',draw, false);
      canvas.addEventListener('touchmove',draw, false);
      canvas.addEventListener('touchend',draw, false);

    // prevent elastic scrolling
    document.body.addEventListener('touchmove',function(event){
      event.preventDefault();
    },false); // end body.onTouchMove

  },false); // end window.onLoad

  function salvarDatos() {
     var canvasData = canvas.toDataURL("image/png");
       var ajax = new XMLHttpRequest();
       ajax.open("POST",'test.php',false);
       ajax.setRequestHeader('Content-Type', 'application/upload');
       ajax.send(canvasData);
     //
     var ajax = new XMLHttpRequest();    
     nombre = document.getElementById('nombre').value;
     numero = document.getElementById('numero').value;
     ajax.open("POST", "testdatos.php",true);
     ajax.onreadystatechange=function() {
    if (ajax.readyState==4) {
      contenedor.innerHTML = ajax.responseText
    }
     }
  ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  ajax.send("numero="+numero+"&nombre="+nombre)
  }
    
asked by JSACTM Music 12.10.2018 в 18:29
source

0 answers