JavaScript (index.html):
Start: <div id="t1"></div> Move: <div id="t2"></div> End: <div id="t3"></div> <script type="text/javascript"> document.ontouchstart = function(e) { var px = e.changedTouches[0].clientX; var py = e.changedTouches[0].clientY; e.preventDefault(); document.getElementById('t1').innerHTML = '(' + px + ', ' + py + ')'; }; document.ontouchmove = function(e) { var px = e.changedTouches[0].clientX; var py = e.changedTouches[0].clientY; e.preventDefault(); document.getElementById('t2').innerHTML = '(' + px + ', ' + py + ')'; }; document.ontouchend = function(e) { var px = e.changedTouches[0].clientX; var py = e.changedTouches[0].clientY; e.preventDefault(); document.getElementById('t3').innerHTML = '(' + px + ', ' + py + ')'; }; </script>
說明:
觸控事件取得座標範例。
沒有留言:
張貼留言