I am using xui-swipe.js for detecting swipe left and right gesture on a Phonegap application.
It is working fine on both android emulator and iPhone simulator. But when I installed this application to real device (Samsung Glaxy S3) swipe gesture detect the event only one time and after that nothing is detected; whether left or right.
Here is chunk of code used to detect the gesture (note that both xui.js and xui-swipe.js are included):
<script type="application/javascript">
function init ()
{
x$("#wrapper").swipe(function(e, data){
var offset = parseInt(sessionStorage.getItem('offset'));
switch(data.direction) {
case 'right':
if (offset>0) {
sessionStorage.setItem('offset', offset-1);
document.location = "file.html";
}
//alert('right');
break;
case 'left':
if (offset<10) {
sessionStorage.setItem('offset', offset+1);
document.location = "file.html";
}else {
document.location = "file-end.html";
}
//alert('left');
break;
}
}, {
swipeCapture: true,
longTapCapture: true,
doubleTapCapture: true,
simpleTapCapture: false
});
}
var _timer=setInterval(function(){
if(/loaded|complete/.test(document.readyState)){
clearInterval(_timer)
init() // call target function
}
}, 10);
</script>
Any help is appreciated.
I think you are case statement is wrong:
You first need to check for the case 'direction', and then check if it is left or right.