æ¯æ¥ãã¢ãã€ã«ã¢ããªã±ãŒã·ã§ã³ã¯ãŸããŸãå°é£ã«ãªã£ãŠããŸãã Webéçºè ã¯ãã¿ããã¹ã¯ãªãŒã³ã®ãã¹ãŠã®æ©èœã䜿çšããããã®APIãå¿ èŠã§ãã ããšãã°ãäžéšã®ã¢ãŒã±ãŒãã²ãŒã ãæ Œéã²ãŒã ã§ã¯ãããã€ãã®ãã¿ã³ãæŒãå¿ èŠããããŸãããã®æ©èœã¯ããã«ãã¿ããããµããŒãããç»é¢ãæäŸã§ããŸãã
Appleã¯iOS 2.0ã§ã¿ããã€ãã³ãAPIãå°å ¥ããŸããããããã«Androidããã€ã¹ããã®æ©äŒãåŸãŠãã¿ããã€ãã³ãAPIã¯äºå®äžã®æšæºã«ãªããŸããã W3Cã¯ãŒãã³ã°ã°ã«ãŒãã¯æè¿ã ã¿ããã€ãã³ãä»æ§ã«åãçµãããã«çµã¿ç«ãŠãããŸããã
ãã®èšäºã§ã¯ãiOSããã³Androidããã€ã¹ãæäŸããã¿ããã€ãã³ãAPIãæ€èšããã¿ããã€ãã³ãAPIã䜿çšããŠäœæã§ããã¢ããªã±ãŒã·ã§ã³ãåŠç¿ããŸãã ãã®èšäºã«ã¯ãã¿ããã€ãã³ãAPIã䜿çšããŠã¢ããªã±ãŒã·ã§ã³ãç°¡åã«äœæã§ãã䟿å©ãªäŸãšãã¯ããã¯ãæ°å€ããããŸãã
ã€ãã³ã
ãããã®3ã€ã®äž»èŠãªã€ãã³ãã¯ä»æ§ã«ç€ºãããŠãããå€ãã®ããã€ã¹ã§ãµããŒããããŠããŸãã
touchstart ïŒDOMèŠçŽ ã«ã¿ããããŸãïŒmousedownã«é¡äŒŒïŒã
touchmove ïŒDOMèŠçŽ ã«æ²¿ã£ãæã®åãïŒmousemoveã«é¡äŒŒïŒã
touchend ïŒDOMèŠçŽ ã§åé€ãããæïŒã¢ããã°ããŠã¹ã¢ããïŒã
åã€ãã³ãã«ã¯ãã¿ãããã€ã³ãã®3ã€ã®ãªã¹ãïŒãã£ã³ã¬ãŒãªã¹ãïŒãå«ãŸããŸãã
touches ïŒç»é¢äžã®ãã¹ãŠã®ã¿ãããã€ã³ãã®ãªã¹ãã
targetTouches ïŒçŸåšã®èŠçŽ ã®ãã€ã³ãã®ãªã¹ãã
changedTouches ïŒçŸåšã®ã€ãã³ãã«åå ããŠããæã®ãªã¹ãã ããšãã°ãtouchendã€ãã³ãã§ã¯ãããã¯åé€ãããæã§ãã
ãªã¹ãã®åèŠçŽ ã¯ã次ã®åœ¢åŒã®ãªããžã§ã¯ãã§ãã
identifier ïŒçŸåšç»é¢äžã«ããæã®äžæã®èå¥å
target ïŒã€ãã³ãã®ç®çã§ããDOMèŠçŽ
ã¯ã©ã€ã¢ã³ã/ããŒãž/ç»é¢åº§æš ïŒ ç»é¢äžã§ã€ãã³ããçºçãããã€ã³ã
radiusãšrotationAngle ïŒæã®åœ¢ãè¡šãæ¥å
ã¿ããã¢ããª
touchstartãtouchmoveãããã³touchendã€ãã³ãã¯ããºãŒã ãå転ãªã©ã®éåžžã®ãã«ãã¿ãããžã§ã¹ãã£ãå«ãã¿ããããŒã¹ã®å¯Ÿè©±ãäœæããããã®åŒ·åãªAPIãæäŸããŸãã
ãã®äŸã§ã¯ãã·ã³ã°ã«ãã€ã³ãã¿ããã䜿çšããŠDOMèŠçŽ ããã©ãã°ã§ããŸãã
var obj = document.getElementById('id'); obj.addEventListener('touchmove', function(event) { // 1 if (event.targetTouches.length == 1) { var touch = event.targetTouches[0]; // Place element where the finger is obj.style.left = touch.pageX + 'px'; obj.style.top = touch.pageY + 'px'; } }, false);
以äžã¯ãç»é¢äžã®ãã¹ãŠã®ã¿ããã衚瀺ããäŸã§ãã
ç»åã¯ã¯ãªãã¯å¯èœã§ã
圌ã®ã³ãŒãã¯æ¬¡ã®ãšããã§ãã
// canvas canvas.addEventListener('touchmove', function(event) { for (var i = 0; i < event.touches.length; i++) { var touch = event.touches[i]; ctx.beginPath(); ctx.arc(touch.pageX, touch.pageY, 20, 0, 2*Math.PI, true); ctx.fill(); ctx.stroke(); } }, false);
ãã¢
å€æ°ã®ãã«ãã¿ããã¢ããªã±ãŒã·ã§ã³ããã§ã«ç»å ŽããŠããŸãããã®ãã¡ã®1ã€ã¯ãPaul Irishã«ãã£ãŠäœæããããã£ã³ãã¹ããŒã¹ã®æç»ããŒã«ã§ãã
Browser Ninjaãã¢ã¯ãCSS3å€æããã©ã³ãžã·ã§ã³ããã£ã³ãã¹ã䜿çšããFruit Ninjaã¯ããŒã³ã§ãã
éèŠãªãã€ã³ã
ãºãŒã é²æ¢
ããã©ã«ãèšå®ã¯ãã«ãã¿ããã«ã¯ããŸãé©ããŠããŸãããå€ãã®å Žåãã¢ãã€ã«ãã©ãŠã¶ã¯ãæã®åãããºãŒã ãŸãã¯ã¹ã¯ããŒã«ã®ã³ãã³ããšããŠèªèããŸãã
ãºãŒã ãç¡å¹ã«ããã«ã¯ã次ã®ã¡ã¿ã¿ã°ãå²ãåœãŠãå¿ èŠããããŸãã
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
ããã«åŸ®èª¿æŽããã«ã¯ã www.html5rocks.com / mobile / mobifying.htmlïŒtoc - meta - viewportã®ãã®èšäºãã芧ãã ããã
ã¹ã¯ããŒã«é²æ¢
äžéšã®ã¢ãã€ã«ããã€ã¹ã«ã¯ãiOSã®å€å žçãªãªãŒããŒã¹ã¯ããŒã«ãªã©ãã¿ããã ãŒããžã§ã¹ãã£ã®ããã©ã«ãã®åäœããããŸããããã«ãããã¹ã¯ããŒã«ã蚱容é床ãè¶ ããå Žåã«ããŒãžãæ»ããŸãã ããã¯ãã«ãã¿ããã¢ããªã±ãŒã·ã§ã³ã§ã¯ãããã«ããã§ãããç°¡åã«ç¡å¹ã«ã§ããŸãã
document.body.addEventListener('touchmove', function(event) { event.preventDefault(); }, false);
æ éã«æã
è€éãªãã«ããã£ã³ã¬ãŒãžã§ã¹ãã£ãå«ããã«ãã¿ããã¢ããªã±ãŒã·ã§ã³ãäœæããå Žåã¯ãå€ãã®ã€ãã³ããåãåãããã泚æãå¿ èŠã§ãã ãã¹ãŠã®ã¿ãããã€ã³ããæç»ãããåã®äŸãèããŠã¿ãŸãããã 次ã®æ¹æ³ã§å®è¡ã§ããŸãã
canvas.addEventListener('touchmove', function(event) { renderTouches(event.touches); }, false);
ãã®æ¹æ³ã¯ãç»é¢äžã®æã®æ°ã«æ¯äŸããŸããã 代ããã«ãã«ãŒãã䜿çšããŠãã¹ãŠã®æãæç»ããããã©ãŒãã³ã¹ãå€§å¹ ã«åäžãããããšãã§ããŸãã
var touches = [] canvas.addEventListener('touchmove', function(event) { touches = event.touches; }, false); // 60fps timer = setInterval(function() { renderTouches(touches); }, 15);
setIntervalã®ã¿ã€ããŒã¯ãã¢ãã¡ãŒã·ã§ã³ãäœæããã®ã«é©ããæ¹æ³ã§ã¯ãããŸããã ãã©ãŠã¶ã®åæç»ãµã€ã¯ã«ãšåæããŸããã ææ°ã®ãã¹ã¯ããããã©ãŠã¶ãŒã¯requestAnimationFrameé¢æ°ãæäŸããŸãããã®é¢æ°ã¯ãã¢ãã¡ãŒã·ã§ã³ã®ã«ãŒãã«é©ããŠããŸã-ããå¹ççã§ãããããªãŒã®æ¶è²»ãå°ãªããªããŸãã ææ°ã®ãã¹ãŠã®ãã©ãŠã¶ã§ãµããŒãããããšãsetIntervalã®äœ¿çšã¯äžé©åãªåœ¢åŒã«ãªããŸãã
targetTouchesããã³changedTouchesã®äœ¿çš
event.touchesã¯ãDOMèŠçŽ ã«è§Šããæã ãã§ãªããç»é¢ã«æ¥è§ŠããŠãããã¹ãŠã®æã®é åã§ããããšãç解ããããšãéèŠã§ãã éåžžãæãé©åãªã®ã¯event.targetTouchesãŸãã¯event.changedTouchesã§ãã
æåŸã«ãã¢ãã€ã«ããã€ã¹çšã«éçºããŠããå Žåã¯ã Eric Bidelmanã®èšäºãšW3Cã®ããã¥ã¡ã³ãã§èª¬æãããŠããéèŠãªãã€ã³ããç¥ã£ãŠããå¿ èŠããããŸã ã
ããã€ã¹ã®ãµããŒã
æ®å¿µãªããããã¹ãŠã®ããã€ã¹ãé©åãªå質ã®ã¿ããã€ãã³ãããµããŒãããŠããããã§ã¯ãããŸããã ãã®ããã€ã¹ãŸãã¯ãã®ããã€ã¹ã«ããã¿ããAPIã®ãµããŒããããã³ã¿ããã ãŒãã®ç²ŸåºŠã«é¢ããæ å ±ã衚瀺ãã蚺æçšã®ã¹ã¯ãªãããäœæããŸãã ã Nexus Oneããã³Nexus Sã§Android 2.3.3ãXoomã§Android 3.0.1ãiPadããã³iPhoneã§iOS 4.2ããã¹ãããŸããã
äžèšã§èšãã°ããããã®ãã©ãŠã¶ãŒã¯ãã¹ãŠãã¿ããã¹ã¿ãŒããã¿ãããšã³ããããã³ã¿ããã ãŒãããµããŒãããŠããŸãã
ä»æ§ã§ã¯ããã«3ã€ã®ã€ãã³ãã«ã€ããŠèª¬æããŠããŸãããã©ã®ãã©ãŠã¶ãŒããããããµããŒãããŠããŸããã
touchenter ïŒæã§DOMèŠçŽ ãå ¥åããŸãã
touchleave ïŒæã¯DOMèŠçŽ ããé¢ããŸãã
touchcancel ïŒäžæãããã¿ããïŒå®è£ ã«äŸåïŒã
ãã¹ãæžã¿ã®ãã¹ãŠã®ãã©ãŠã¶ãŒã¯ãã¿ãããªã¹ãïŒtouchãtargetTouchesãchangedTouchesïŒãæäŸããŸãã ãã ããã©ã®ãã©ãŠã¶ãæã®åœ¢ç¶ã決å®ããradiusXãradiusYãrotationAngleã®ãããããµããŒãããŠããŸããã
Touchmoveã€ãã³ãã¯ããã¹ãããããã¹ãŠã®ããã€ã¹ã§æ¯ç§çŽ60åçºçããŸãã
Android 2.3.3ïŒNexusïŒ
Android Gingerbreadãã©ãŠã¶ãŒïŒNexus Oneããã³Nexus SïŒã«ã¯ãã«ãã¿ãããµããŒãããããŸããã ããã¯æ¢ç¥ã®åé¡ã§ãã
Android 3.0.1ïŒXoomïŒ
Xoomãã©ãŠã¶ã¯ãã«ãã¿ããããµããŒãããŠããŸããã1ã€ã®DOMèŠçŽ ã§ã®ã¿æ©èœããŸãã ãã©ãŠã¶ã¯ãç°ãªãDOMèŠçŽ ã§2ã€ã®äžŠåã€ãã³ããæ£ããåŠçã§ããŸããã ã€ãŸãã次ã®ã³ãŒãã¯2ã€ã®äžŠåã€ãã³ããåŠçããŸãã
obj1.addEventListener('touchmove', function(event) { for (var i = 0; i < event.targetTouches; i++) { var touch = event.targetTouches[i]; console.log('touched ' + touch.identifier); } }, false);
ããããããã¯ããã§ã¯ãããŸããïŒ
var objs = [obj1, obj2]; for (var i = 0; i < objs.length; i++) { var obj = objs[i]; obj.addEventListener('touchmove', function(event) { if (event.targetTouches.length == 1) { console.log('touched ' + event.targetTouches[0].identifier); } }, false); }
iOS 4.xïŒiPadãiPhoneïŒ
IOSããã€ã¹ã¯ãTouch APIãå®å šã«ãµããŒãããŠããŸãã
éçºè ããŒã«
ã¢ãã€ã«éçºã§ã¯ãã³ã³ãã¥ãŒã¿ãŒäžã§ãããã¿ã€ããäœæããå¿ èŠã«å¿ããŠã©ã€ãã®ã¢ãã€ã«ããã€ã¹ã䜿çšããŠãã¹ãããæ¹ãç°¡åã§ãã å€ãã®PCã¯ãã«ãã¿ããããµããŒãããŠããªãããããã«ãã¿ããã¯éåžžã®PCã§ãã¹ãããã®ãé£ããããšã®1ã€ã§ãã
ã¢ãã€ã«ããã€ã¹ã§ã®ãã¹ãã®å¿ èŠæ§ã¯ãéçºãµã€ã¯ã«ãå¢å ãããå¯èœæ§ããããŸãã åå€æŽããµãŒããŒã«ã¢ããããŒãããŠãããããã€ã¹ã«ã¢ããããŒãããå¿ èŠããããŸãïŒãããããéåžžã«çãããé£æ床ã§ãïŒã ã¢ãã€ã«ããã€ã¹ã«ã¯ãå¿ èŠãªéçºè ããŒã«ããããŸããã
ãã®åé¡ã®è§£æ±ºçã¯ãPCã§ã¿ããã€ãã³ããã·ãã¥ã¬ãŒãããããšã§ãã ã¯ã³ãã€ã³ãã¿ããã¯ããŠã¹ã§ã·ãã¥ã¬ãŒãã§ããŸãã ãã«ãã¿ããã¯ããã«ãã¿ããããµããŒãããããã€ã¹ãããšãã°æ°ããApple MacBookã§ã·ãã¥ã¬ãŒãã§ããŸãã
ã·ã³ã°ã«ãã€ã³ãã€ãã³ã
PCã§ã¯ã³ãã€ã³ãã€ãã³ããã·ãã¥ã¬ãŒãããå Žåã¯ãããŒãžäžã®ã¿ããã€ãã³ããã·ãã¥ã¬ãŒãããPhantom Limbãè©ŠããŠãã ããã
ããŠã¹ãšã¿ããã€ãã³ããçµã¿åãããjQueryçšã®Touchableãã©ã°ã€ã³ããããŸãã
ãã«ãã¿ããã€ãã³ãïŒMACã®ã¿ã®ãœãªã¥ãŒã·ã§ã³ïŒ
ãã«ãã¿ããããã€ã¹ïŒApple MacBookãŸãã¯MagicPadïŒã䜿çšããŠããã©ãŠã¶ãŒã§ãã«ãã¿ããã€ãã³ããåŠçã§ããããã«ããŸãã MagicTouch.jsãäœæããŸãããããã¯ããã©ãã¯ãããããã€ãã³ãããã£ããããæšæºãšäºææ§ã®ããã€ãã³ãã«å€æããŸãã
éå§ããã«ã¯ïŒ
1.ã / Library / Internet Plug-Ins /ã«npTuioClient NPAPIãã©ã°ã€ã³ãããŠã³ããŒãããŠã€ã³ã¹ããŒã«ããŸãã
2. MagicPadçšTongSeng TUIOã¢ããªãããŠã³ããŒããããµãŒããŒãèµ·åããŸãã
3. MagicTouch.js JavaScriptã©ã€ãã©ãªãããŠã³ããŒãããŠãæšæºãšäºææ§ã®ããã¿ããã€ãã³ããã·ãã¥ã¬ãŒãããŸãã
4. magictouch.jsãšnpTuioClientãã©ã°ã€ã³ãæ¥ç¶ããŸãã
<head> ... <script src="/path/to/magictouch.js"></script> </head> <body> ... <object id="tuio" type="application/x-tuio" style="width: 0px; height: 0px;"> Touch input plugin failed to load! </object> </body>
ãã®æ¹æ³ã¯Chrome 10ã§ã®ã¿ãã¹ãããŸããããä»ã®ææ°ã®ãã©ãŠã¶ãŒã§ãåäœããã¯ãã§ãã
ã䜿ãã®PCããã«ãã¿ããããµããŒãããŠããªãå ŽåãreacTIVisionãªã©ã®ä»ã®TUIOãã©ãã«ãŒã䜿çšããŠã¿ããã€ãã³ããã·ãã¥ã¬ãŒãã§ããŸãã 詳现æ å ±ã¯ã TUIOãããžã§ã¯ãã®Webãµã€ãã§å ¥æã§ããŸãã
ãžã§ã¹ãã£ã¯OSãžã§ã¹ãã£ãšéè€ããå ŽåããããŸãã OS Xã§ã¯ã [ã·ã¹ãã ç°å¢èšå®]> [ãã©ãã¯ããã]ã§ã·ã¹ãã ã€ãã³ããèšå®ã§ããŸã
ãã«ãã¿ããã€ãã³ãã¯ããŸããŸãå€ãã®ã¢ãã€ã«ãã©ãŠã¶ã§ãµããŒããããŠããŸãããæ°ããWebã¢ããªã±ãŒã·ã§ã³ããã®APIãå šé¢çã«äœ¿çšããŠããããšãéåžžã«å¬ããæããŸãã
翻蚳è ãã
å ã®èšäºãžã®ã³ã¡ã³ãã§ã¯ããªã³ã¯ãæ»ããŸããïŒ iPhoneã§ã®ã¿ãããšãžã§ã¹ãã£ãŒ
ææ¡ãåžæãæ¹å€ã¯å€§æè¿ã§ãïŒ