如何在ipad中使用safari在canvas元素中绘制?
我试图实现一个画布元素来触摸登录safari / ipad。 我已经为桌面浏览器做了mousedown mouseup和mousemove事件。 我必须使用哪些事件才能在iPad中做同样的事情? touchstart,touchend和touchmove?
这是我的功能
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/95583.html上一篇: How can I draw in canvas element with safari in ipad?
下一篇: touch events stop firing when dragging down on mobile Safari