Using phonegap, jquery.
Is it possible to detect touches on two different elements at the same time ?
I’m creating something that requires two images ( button-left and button-right ) to be pressed
at the same time before another event it triggered.
The following is not an exhaustive list of code, but should provide insight into what im trying to achieve
<head>
<script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script>
<script type="text/javascript" charset="utf-8" src="jq.js"></script>
<script type="text/javascript" src="jquery.stopwatch.js"></script>
<script>
var w = new Stopwatch(updatedisplay, 50);
var onoff = false;
$("#button-left, #button-right").unbind("touch",begin);
function begin() {
onoff = true;
w.start();
}
function end() {
w.stop();
onoff = false;
}
function updatedisplay(watch) {
var mills = parseInt(watch.getElapsed().milliseconds/10);
if(mills<10) {
millis = '0'+mills;
} else {
millis = mills;
}
document.getElementById('counterValue').innerHTML = watch.toString() + "." + millis;
}
function reset() {
w.stop();
onoff = false;
document.getElementById('counterValue').innerHTML = "00:00:00.00";
}
</script>
</head>
<body onload="onBodyLoad()">
<div id="counterValue">
00:00:00.00
</div>
<div id="button-left"></div>
<div id="button-right"></div>
</body>
::::: CREATED THIS FIX ::::: A BIT UGLY BUT IT WORKS BRILLIANTLY :::::
I found another way around, now this might be a bit ugly.. but it works well …
$(document).ready(function() {
document.getElementById('button-left').addEventListener('touchstart', nofunc(e), false);
document.getElementById('button-right').addEventListener('touchstart', nofunc(e), false);
});
function vala(val) {
av = val;
checkvals();
}
function valb(val) {
bv = val;
checkvals();
}
function checkvals() {
if(av == 1 && bv == 1) {
if(onoff == false) {
begin();
} else {
end();
}
}
}
<div id="button-left" ontouchstart="vala(1)" ontouchend="vala(0)"> </div>
<div id="button-right" ontouchstart="valb(1)" ontouchend="valb(0)"> </div>
as above, i found a way to do what i needed… a bit of “reading of manuals” and i came up with this