2011-01-28 4 views

답변

15

다음은 touchstarttouchend을 보여주는 예입니다. 터치 이벤트를 첨부하는 두 가지 방법 : 요소 속성 또는 JavaScript addEventListener을 보여줍니다.

터치 이벤트를 수신 중이므로 마우스 이벤트를 지원하는 데스크톱 브라우저에서 이벤트가 실행되지 않습니다. 페이지를 테스트하려면 Android 또는 iOS 시뮬레이터를 열 수 있습니다.

<!DOCTYPE html> 
<html> 
    <head> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0;" /> 
    <style type="text/css"> 
     a { 
     color:black; 
     display:block; 
     margin:10px 0px; 
     } 
    </style> 

    <script type="text/javascript"> 
     function onload() { 
     document.getElementById('touchstart').addEventListener('touchstart', hello, false); 
     document.getElementById('touchend').addEventListener('touchend', bye, false); 
     } 

     function hello() { 
     alert('hello'); 
     } 

     function bye() { 
     alert('bye'); 
     } 
    </script> 

    <title>Touch Example</title> 
    </head> 
    <body onload="onload();"> 
    <h1>Touch</h1> 
    <a href="#" ontouchstart="hello();return false;">Attribute: ontouchstart</a> 
    <a href="#" ontouchend="bye();return false;">Attribute: ontouchend</a> 
    <a href="#" id="touchstart">addEventListener: touchstart</a> 
    <a href="#" id="touchend">addEventListener: touchend</a> 
    </body> 
</html> 
+0

좋아, 내가 감사에게 .. 내가 밖으로 시도 – Dayzza

+0

@mwbrroks을 다할 것입니다 그것은 링크/버튼과 함께 사용하기에 적합합니다. 그러나 그것이 어떤 링크 또는 버튼도없이 빈 화면에서 작동 할 수 있는지 궁금 해서요. 긴 사용자가 화면 어디서나 그것이 팝업을 표시합니다 터치 의미. 가능한가요? :) thanks – Dayzza

+0

Do a window.addEventListener (etc) – Harry

관련 문제