2013-01-17 37 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 ,其餘全部都是爲觸摸操作而生成的。

請檢查這些。希望它有幫助