2

我正在尝试实现一个画布元素以在 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();
}
4

1 回答 1

1

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

于 2012-10-15T12:27:24.217 回答