i m using a version of the code found ove here
var startTime, endTime;
document.getElementById(queryid).addEventListener('touchstart',function() {
startTime = new Date().getTime();
},false);
document.getElementById(queryid).addEventListener('touchend',function(event) {
endTime = new Date().getTime();
if((endTime-startTime) > 1000)
alert('tap hold event');
},false);
it does the "trick" of tap and hold before someaction, but my problem is that action is triggered only if i stop touching the screen, while i want action to be triggered after tapping for at least i.e. 1sec no matter if i stop touching the screen or not..
this one seems closer to what i want, but it doesn't seem complete..(to my understanding.. gbStillTouching is always false? i don't see anywhere getting toggled.. gnstarttime ==nid? isn't nid=gnstarttime?
var gnStartTime = 0;
var gbMove = false;
var gbStillTouching = false;
function checkTapHold(nID) {
if ((!gbMove) && (gbStillTouching) && (gnStartTime == nID)) {
gnStartTime = 0;
gbMove = false;
alert('tap hold event');
}
}
window.addEventListener('touchstart',function(event) {
gnStartTime = Number(new Date());
setTimeout('checkTapHold(' + gnStartTime + ');clearTimeout();',2000);
},false);
window.addEventListener('touchmove',function(event) {
gbMove = true;
},false);
window.addEventListener('touchend',function(event) {
gbStillTouching = false;
},false);
here is the solution to the problem, after some useful help from a friend..
this works perfectly..after having tapped for at least 1 sec, i can have the required action.. :)