2012-09-11 62 views
0

我正在使用xui-swipe.js來檢測Phonegap應用程序上的左右手勢。xui輕掃手勢不能在真實設備上工作

它在Android模擬器和iPhone模擬器上工作正常。但是,當我將此應用程序安裝到真實設備(Samsung Glaxy S3)時,輕掃手勢僅檢測一次事件,之後沒有檢測到任何事件;無論是向左還是向右。

下面是用於檢測手勢代碼塊(注意,這兩個xui.jsxui-swipe.js包括):

<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> 

任何幫助理解。

回答

0

我認爲你是case語句是錯誤的:

switch (data.type){ 
    case ('direction'): 
     if (data.direction == 'left') { 
     i--; 
     } else { 
     i++; 
    } 

首先,您需要檢查的情況下,「方向」,然後檢查其是否向左或向右。