테스트 목적으로 모바일 브라우저에서 터치 이벤트를 트리거하는 방법을 파악하려고합니다. 나는 웹 개발자가 아니기 때문에 이것은 나에게 익숙하지 않은 영토이다.모바일 웹에서 터치 이벤트 트리거
이 시점에서 나는 화면을 터치하고 동일한 응답을 트리거하기 위해 다시 발사 한 실제 터치 이벤트를 캡처하려고합니다. 아래는 내가 실제로 amazon.com 페이지에서하는 일입니다. 슬라이딩을 반복하기를 원하는 컨베이어가 실제로 손가락으로 미끄러지는 것처럼 말입니다. 그러나 회전 목마는 미끄러지지 않습니다. 브라우저가 내 재발행 된 이벤트를 원래 이벤트와 다르게 처리하는 것 같습니다. Android에서 Chrome에서이 작업을 실행하고 있습니다.
누구든지이 동작을 보았고 무엇을 해결해야합니까?
// EDITED after taking into consideration @Palpatim's suggestion
// stash away events on a carousel
var element = document.querySelector('.gw-carousel-viewport');
document.test_touch_move = []
element.addEventListener('touchstart', function(e){document.test_touch_start = e;}, false);
element.addEventListener('touchmove', function(e){document.test_touch_move.push(e);}, false);
element.addEventListener('touchend', function(e){document.test_touch_end = e;}, false);
//
// physically slide the carousel with my finder to trigger events
//
// store captured events from being overriden
var touch_start = document.test_touch_start;
var touch_move = document.test_touch_move;
var touch_end = document.test_touch_end;
//
// physically slide the carousel back to its initial position to make sure all event screen coordinates match
//
element.dispatchEvent(touch_start);
touch_move.forEach(function(e){element.dispatchEvent(e);});
element.dispatchEvent(touch_end);
// I do not see the same sliding behavior as I see when actually swiping with my finger
덕분에, 당신이 올바른지 - 나는 모든하는 TouchMove 이벤트를 캡처하지 않았다. 이러한 이벤트를 캡처하고 재생하기 위해 예제 코드 예제를 편집했습니다. 그러나, 나는 회전 목마가 움직이는 것을 아직도 보지 않는다. – osjak