触摸绘制事件和 HTML5 Canvas
我正在尝试编写一个可以用鼠标和移动设备(iOS/Android)“绘制”的画布元素。
这是我的绑定代码:
// Mouse based interface $(drawing.canvas).bind('mousedown', drawing.drawStart); $(drawing.canvas).bind('mousemove', drawing.draw); $(drawing.canvas).bind('mouseup', drawing.drawEnd); $('body').bind('mouseup', drawing.drawEnd); $(drawing.canvas).bind('touchstart', drawing.drawStart); $(drawing.canvas).bind('touchmove', drawing.draw); $(drawing.canvas).bind('touchend', drawing.drawEnd);
适用于计算机(PC、Mac),但不适用于移动设备(iOS/Android)。我还尝试了 addEventListener
来处理 touch*
事件,但没有任何乐趣。
有什么想法吗?
I'm trying to write a canvas element that can be 'draw' on with the mouse and mobile (iOS/Android).
here is my bind code:
// Mouse based interface $(drawing.canvas).bind('mousedown', drawing.drawStart); $(drawing.canvas).bind('mousemove', drawing.draw); $(drawing.canvas).bind('mouseup', drawing.drawEnd); $('body').bind('mouseup', drawing.drawEnd); $(drawing.canvas).bind('touchstart', drawing.drawStart); $(drawing.canvas).bind('touchmove', drawing.draw); $(drawing.canvas).bind('touchend', drawing.drawEnd);
Works with computer (PC, Mac) but not mobile (iOS/Android). I also tried addEventListener
for the touch*
events but no joy.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这要么是语法错误,要么是 jQuery 问题。总结一下,
canvas.addEventListener( 'touchstart', onTouchStart, false);
对于 android 来说效果很好:http://jsfiddle.net/tQW2L/
(触摸时会绘制一个大的黑色矩形以确认其有效)
It is either a sytax error or a jQuery problem. Distilled down,
canvas.addEventListener( 'touchstart', onTouchStart, false);
works just fine for android:http://jsfiddle.net/tQW2L/
(on touch it paints a large black rectangle to confirm that it works)