2016-08-30 9 views
0

터치 스크린에서 스 와이프 감지를 위해 jquery mobile을 사용하고 있습니다. swipe 이벤트를 듣고 싶지만 두 개 이상의 손가락이 화면을 터치하는 경우에만 작업을 수행하십시오. 정상적인 터치 이벤트는 이벤트 내에서 touches 배열을 통해 감지 할 수 있지만, swipe이 발생한 후 이벤트를 확인하면 존재하지 않는 것 같습니다. 누구든지 swipe 이벤트가 발생한 후 touches 어레이에 액세스 할 수있는 방법에 대해 올바른 방향으로 알려줄 수 있습니까?jquery mobile - 스 와이프 이벤트에서 배열을 감지합니다.

+0

어떤 것을 시도 했습니까? – Mansuro

답변

0

jquery mobile이 아니라는 것을 알았습니다. 재정의해야하지만 슬라이드 쇼 플러그인을 사용하고있었습니다 (jquery cycle2). 내 코드는 다음과 같습니다.

window.global_touches = null; 

$('.page').on({ 
    touchstart: function(e) { 
     e.preventDefault(); 
     window.global_touches = e.originalEvent.touches; 
    }, 
    touchmove: function(e) { 
     window.global_touches = e.originalEvent.touches; 
    }, 
    touchend: function(e) { 
     window.global_touches = e.originalEvent.touches; 
    }, 
    touchcancel: function(e) { 
     window.global_touches = e.originalEvent.touches; 
     clearHighlight(); 
    } 
}); 

$('.inner-slideshow').on('cycle-bootstrap', function(e, optionHash, API) { 
    API.origAdvanceSlide = API.advanceSlide; 
    API.advanceSlide = function(numberOfPositions) { 
     if (window.global_touches && window.global_touches.length >= 2) { 
      API.origAdvanceSlide.call(API, numberOfPositions); 
     } 
    }; 
});