touchstart
및 touchmove
이벤트 (이 경우에는 touchend
이벤트가 있지만 필요하지는 않음)를 사용해야하며, 마우스 이벤트와 동일한 방식으로 작동합니다.
다음은 이전에 개인적으로 사용한 적이없는 개념의 예입니다.
var startX = 0, startY = 0;
$('.selector.').bind('touchstart', function(event) {
startX = event.touches[0].pageX;
startY = event.touches[0].pageY;
});
$('.selector.').bind('touchmove', function(event) {
endX = event.touches[0].pageX;
endY = event.touches[0].pageY;
if (startX - 100 < endX)
{
// SWIPE LEFT CODE HERE
// The startX - 100 is to give some leeway for the user, they have to
// move there finger at least 100 pixel difference to the left to trigger
}
elseif (endX > startX + 100)
{
// SWIPE RIGHT CODE HERE
// The startX + 100 is to give some leeway for the user, they have to
// move there finger at least 100 pixel different to the right to trigger
}
});
기본 개념은 당신이 touchstart
이벤트를 가지고 있고이 시작 위치와 x는 그들이 왼쪽 강타하고 낮은 경우가, 강타하는 방법을 결정하는 touchmove
이벤트를 기록하고, 바로 그때 높은 X y가 높을수록 위로, y가 내려 가면서 내려 간다.
이것은 좋은 자료입니다. http://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html
도움을 주셔서 감사합니다. – Marvin3