- touchstart - mouseDown 이벤트와 비슷한 이벤트로 손이 화면에 닿으면 발생
- touchmove - mouseMove 이벤트와 비슷한 이벤트로 손 터치한 상태로 이동하면 발생
- touchend - mouseUp 이벤트와 비슷한 이벤트로 손을 화면에서 뗄때 발생. 아이폰의 경우 touchcancel 이벤트가발생
- touchcancel - bit of a mystery 라고 표현하네요. 쬐금 이상하다는...
document.addEventListener('touchstart', function(event) {
alert(event.touches.length);
}, false);
Event objectdocument.addEventListener('touchmove', function(event) {
event.preventDefault();
var touch = event.touches[0];
console.log("Touch x:" + touch.pageX + ", y:" + touch.pageY);
}, false);
- clientX: X coordinate of touch relative to the viewport (excludes scroll offset)
- clientY: Y coordinate of touch relative to the viewport (excludes scroll offset)
- screenX: Relative to the screen
- screenY: Relative to the screen
- pageX: Relative to the full page (includes scrolling)
- pageY: Relative to the full page (includes scrolling)
- target: Node the touch event originated from
- identifier: An identifying number, unique to each touch event
iPhone Touch and Gesture Events
애플의 WebKit은 안드로이드와 달리 몇가지 것들을 추가적으로 지원한다. touchEnd 이벤트는 event.touches array에서 현재 touch 를 제거해준다. 대신 event.changeTouches array를 이용해서 볼 수 있다.- touches - touchStart, touchMove, touchEnd 의 터치 정보를 포함하고 있는 array
- targetTouches - 같은 target Element로부터 비롯된 touches 정보를 포함
- changedTouches - 모든 touch 정보를 가지고 있는 객체
Gesture events
애플에서는 pinching, rotating과 같은 멀티 터치 이벤트를 처리할 수 있도록 지원한다.- gesturestart - 멀티 터치 시작
- gesturechange - 멀티 터치를 해서 움직일 때 발생
- gestureend - 멀티 터치 이벤트가 끝날때 발생
예제 )
document.addEventListener('gesturechange', function(event) {
event.preventDefault();
console.log("Scale: " + event.scale + ", Rotation: " + event.rotation);
}, false);
Event table
| touchstart | touchmove | touchend | gesturestart | gesturemove | gestureend | |
|---|---|---|---|---|---|---|
| Android |
y |
y |
y |
n |
n |
n |
| iPhone |
y |
y |
y |
y |
y |
y |
| has event.touches |
y |
y |
y |
n |
n |
n |
| (iPhone) has event.scale and
event.rotation |
n |
n |
n |
y |
y |
y |
| (iPhone) touch in event.touches |
y |
y |
n |
- |
- |
- |
| (iPhone) touch in
event.changedTouches |
y |
y |
y |
- |
- |
- |
회전레이어 연습.html