<canvas> Réaliser une signature
Bonjour,
Un petit coup de main ne serais pas de refus, car cela ne marche pas.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| class Canvas {
constructor() {
this.canvas = document.getElementById('sign');
this.ctx = this.canvas.getContext('2d');
this.dessin = false;
this.init();
this.start();
this.stop();
}
init(){
this.canvas.addEventListener('mousedown', function(){
this.dessin = true;
}.bind(this));
}
start(){
this.canvas.addEventListener("mousemove", function(event){
if(this.dessin === true){
this.ctx.beginPath();
this.ctx.lineWidth = 3;
this.ctx.strokeStyle= "black";
this.ctx.linecap = "round";
this.ctx.moveTo(event.clientX, event.clientY);
this.ctx.lineTo(event.clientX, event.clientY);
this.ctx.stroke();
}}.bind(this));
}
stop(){
this.canvas.addEventListener("mouseup",function(){
if(this.dessin === true){
this.dessin = false;
}}.bind(this));
}
} |
Merci.