How can I draw in canvas element with safari in ipad?

I´m trying to implement a canvas element to touch sign in safari/ipad. I have done it for desktop browsers with mousedown mouseup and mousemove events. Wich events I have to use for do the same in ipad? touchstart,touchend and touchmove?

here is my function

var pizarra_canvas
var pizarra_context

function init(){


    alert('2')
    pizarra_canvas = document.getElementById("pizarra");
    pizarra_context = pizarra_canvas.getContext("2d");
    pizarra_context.strokeStyle = "#000";
    pizarra_canvas.addEventListener('touchstart',empezarPintar,false);
    pizarra_canvas.addEventListener('touchend',terminarPintar,false);
alert('1')
}

function empezarPintar(e){
pizarra_context.beginPath();
pizarra_context.moveTo(e.clientX-pizarra_canvas.offsetLeft,e.clientY-          pizarra_canvas.offsetTop);
pizarra_canvas.addEventListener('touchmove',pintar,false)
}

function terminarPintar(e){
pizarra_canvas.removeEventListener('touchmove',pintar,false);
}

function pintar(e) {
pizarra_context.lineTo(e.clientX-pizarra_canvas.offsetLeft,e.clientY-    pizarra_canvas.offsetTop);
pizarra_context.stroke();
}

我建议你看一下像http://www.kineticjs.com/或http://paper.s.s/这样的框架,它们在触摸屏上处理画布时会有很大的帮助。

链接地址: http://www.djcxy.com/p/95584.html

上一篇: iPad上有两个页面抓取点击事件

下一篇: 如何在ipad中使用safari在canvas元素中绘制?