Je veux dessiner sur une toile, fonctionne très bien avec une souris, mais comment dois-je modifier le code pour le faire fonctionner sur iPad ou Nexus?Dessiner sur une toile via la souris et appuyez sur
[link] http://jsfiddle.net/FgNQk/6/
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var width = window.innerWidth;
var height = window.innerHeight;
canvas.height = height;
canvas.width = width;
canvas.addEventListener('mousedown', function(e) {
this.down = true;
this.X = e.pageX ;
this.Y = e.pageY ;
}, 0);
canvas.addEventListener('mouseup', function() {
this.down = false;
}, 0);
canvas.addEventListener('mousemove', function(e) {
if(this.down) {
with(ctx) {
beginPath();
moveTo(this.X, this.Y);
lineTo(e.pageX , e.pageY);
ctx.lineWidth=1;
stroke();
}
this.X = e.pageX ;
this.Y = e.pageY ;
}
}, 0);
Alors ce que vous avez essayé tellement loin? – robertc
Je pense qu'il suffit d'échanger 'mousedown' et d'écrire 'touchdown' alors ça marchera pour iPad. – user1477955
J'ai essayé avec touchdown, mais ça ne marche pas: [link] http://jsfiddle.net/FgNQk/7/ – daisy