2013-01-17 40 views
-1

我试图让音频声音在触摸上播放,但不能一直工作,它的工作在股票和海豚在Android上,但它不工作在iPad上。我曾尝试过在触动开始时使用mousedown,onclick,touchstart。他们都不是工作Mousdown相当于手机

<canvas id="scratcher1" class="scratchMe" width="99px" height="89px" onmousedown="alert(down)" onclick="alert(click)" touchstart="alert(touch)" ontouchstart="alert(ontouch)"></canvas> 
<canvas id="scratcher2" class="scratchMe" width="99px" height="89px" onmousedown="scratch.play()"></canvas> 

这是在什么现在它,切换到警报,所以我可以尝试找出哪些工作,就像我说的也不是。

回答

0

管理通过此论坛找到答案。

http://www.dynamicdrive.com/forums/showthread.php?65787-How-to-combine-eventhandlers-for-mouse-and-touchscreen-(e-g-iPad)与iPad

类似的情况出现。

<script type="text/javascript"> 

(函数(){ VAR 第一=的document.getElementById( 'scratcher1'), 第二=的document.getElementById( 'scratcher2'); 第三=的document.getElementById( 'scratcher3'); 第四=的document.getElementById( 'scratcher4'); 第五=的document.getElementById( 'scratcher5'); 第六=的document.getElementById( 'scratcher6'); 第七=的document.getElementById( 'scratcher7'); 第八= document.getElementById('scratcher8');

first.ontouchstart = second.ontouchstart = third.ontouchstart = fourth.ontouchstart = fifth.ontouchstart = sixth.ontouchstart = seventh.ontouchstart = eighth.ontouchstart = function() { 
    scratch.play() 
}; 

})();

终于搞定了。

0

可以活动程序化添加到画布上,用JavaScript初始化代码:

document.getElementById("scratcher1").addEventListener("mousedown", alert, false); 

它想工作。

ontouchstart ontouchmove ontouchend 的onclick

只ontouchmove可避免:“应对在画布上鼠标和触摸事件”

0

所有触控操作提供了以下触摸操作顺序下 更多关于此here ,其余全部都是为触摸操作而生成的。

请检查这些。希望它有帮助