-
터치와 클릭 이벤트 다루기problems 2020. 12. 3. 03:04
문제
반응형 웹을 구현하기 위해서는
터치 이벤트와 클릭 이벤트를 같은 요소에 함께 사용해야 했습니다.
해결
터치와 클릭을 구분하여 이벤트를 설정하는 방법입니다.
if ('ontouchstart' in window) { // set up event listeners for touch target.addEventListener('touchend', ...); ... } else { // set up event listeners for mouse/keyboard target.addEventListener('click', ...); ... }
참고
Touch Events - Level 2
The user agent may dispatch both touch events and (for compatibility with web content not designed for touch) mouse events [[!DOM-LEVEL-2-EVENTS]] in response to the same user input. If the user agent dispatches both touch events and mouse events in respon
w3c.github.io
'problems' 카테고리의 다른 글