{"id":701,"date":"2014-07-25T11:39:25","date_gmt":"2014-07-25T06:09:25","guid":{"rendered":"http:\/\/www.prasadk.com\/my-press\/?p=701"},"modified":"2014-07-25T11:52:01","modified_gmt":"2014-07-25T06:22:01","slug":"hammer-js-start-touch-gestures-multitouch","status":"publish","type":"post","link":"https:\/\/www.prasadk.com\/my-press\/hammer-js-start-touch-gestures-multitouch\/","title":{"rendered":"All about hammer.js a start to touch gestures and multitouch"},"content":{"rendered":"<h2>All about hammer.js a start to touch gestures and multitouch<\/h2>\n<p>Hammer is a open-source JavaScript Library for adding touch gestures support that can recognize gestures made by touch, mouse and pointerEvents to any website so that users can interact with them easier on touch devices. It doesn&#8217;t have any dependencies, and it&#8217;s small, only <strong>3.71 kB minified + gzipped<\/strong>!<\/p>\n<p>It\u00a0supports<strong> tap, double tap, press, hold, drag, <em>horizontal pan and swipe<\/em> and the multi-touch pinch and rotate recognizers and also transform<\/strong>.<\/p>\n<h2 id=\"getting-started\">Getting Started<\/h2>\n<ul>\n<li><a href=\"http:\/\/hammerjs.github.io\/dist\/hammer.min.js\">Minified code (v2.0.1)<\/a><\/li>\n<li><a href=\"http:\/\/hammerjs.github.io\/dist\/hammer.js\">Uncompressed code (v2.0.1)<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/hammerjs\/hammer.js\/tree\/master\/\">Browse the source on GitHub<\/a><\/li>\n<li>Looking for the 1.1 version? <a href=\"https:\/\/github.com\/hammerjs\/hammer.js\/tree\/1.1.x\">You can find it here.<\/a><\/li>\n<\/ul>\n<blockquote>\n<h5 id=\"what-s-new-in-2-0-\">What&#8217;s new in 2.0?<\/h5>\n<p>It&#8217;s completely rewritten, with reusable gesture recognizers, and improved support for the recent mobile browsers by making use of the touch-action css property when possible. Also support for multiple Hammer instances the same time, so multi-user became possible.<\/p><\/blockquote>\n<hr \/>\n<h3 id=\"usage\">Usage<\/h3>\n<p>It&#8217;s easy to use, just include the library and create a new instance.<\/p>\n<pre><code>var hammertime = new Hammer(myElement, myOptions);\r\nhammertime.on('pan', function(ev) {\r\n    console.log(ev);\r\n});\r\n<\/code><\/pre>\n<p>By default it adds a set of <code>tap<\/code>, <code>doubletap<\/code>, <code>press<\/code>, <em>horizontal<\/em> <code>pan<\/code> and <code>swipe<\/code>, and the multi-touch <code>pinch<\/code> and <code>rotate<\/code> recognizers. The pinch and rotate recognizers are disabled by default because they would make the element blocking, but you can enable them by calling:<\/p>\n<pre><code>hammertime.get('pinch').set({ enable: true });\r\nhammertime.get('rotate').set({ enable: true });\r\n<\/code><\/pre>\n<p>Enabling vertical or all directions for the <code>pan<\/code> and <code>swipe<\/code> recognizers:<\/p>\n<pre><code>hammertime.get('pan').set({ direction: Hammer.DIRECTION_ALL });\r\nhammertime.get('swipe').set({ direction: Hammer.DIRECTION_VERTICAL });\r\n<\/code><\/pre>\n<p>Also the viewport meta tag is recommended, it gives more control back to the webpage by disableing the doubletap\/pinch zoom. More recent browsers that support the touch-action property don&#8217;t require this.<\/p>\n<pre><code>&lt;meta name=\"viewport\" content=\"user-scalable=no, width=device-width,\r\n initial-scale=1, maximum-scale=1\"&gt;\r\n<\/code><\/pre>\n<h3 id=\"more-control\">More control<\/h3>\n<p>You can setup your own set of recognizers for your instance. This requires a bit more code, but it gives you more control about the gestures that are being recognized.<\/p>\n<pre><code>var mc = new Hammer.Manager(myElement, myOptions);\r\n\r\nmc.add( new Hammer.Pan({ direction: Hammer.DIRECTION_ALL, threshold: 0 }) );\r\nmc.add( new Hammer.Tap({ event: 'quadrupletap', taps: 4 }) );\r\n\r\nmc.on(\"pan\", handlePan);\r\nmc.on(\"quadrupletap\", handleTaps);\r\n<\/code><\/pre>\n<p>The example above creates an instance containing a <code>pan<\/code> and a <code>quadrupletap<\/code> gesture. The recognizer instances you create a being executed in the order they are added, and only one can be recognized at the time.<\/p>\n<h3 id=\"simultaneous-recognizing\">Simultaneous recognizing<\/h3>\n<p>If you want to recognize two gestures simultaneously, you can use the the <code>recognizeWith()<\/code> method. The example below does this with the pinch and rotate recognizers, which will improve usability.<\/p>\n<pre><code>var pinch = new Hammer.Pinch();\r\nvar rotate = new Hammer.Rotation();\r\npinch.recognizeWith(rotate);\r\n<\/code><\/pre>\n<p>Now Hammer is able to run pinch and rotate the same time. You can also separate them with the <code>dropRecognizeWith()<\/code> method on the recognizer instance.<\/p>\n<div>\n<h3 id=\"require-failure-of-an-other-recognizer\">Require failure of an other recognizer<\/h3>\n<p>With the method <code>requireFailure()<\/code> you can let a recognizer require the failure of an other recognizer before recognizing. This could become useful when you want to nest two gestures, like pan-horizontal and pan-vertical. Removing the dependency could be done with the <code>dropRequireFailure()<\/code> method.<\/p>\n<pre><code>var horizontal = new Hammer.Pan({\r\n    event: 'panh',\r\n    direction: Hammer.DIRECTION_HORIZONTAL\r\n});\r\nvar vertical = new Hammer.Pan({\r\n    event: 'panv',\r\n    direction: Hammer.DIRECTION_VERTICAL\r\n});\r\nvertical.requireFailure(horizontal);\r\n<\/code><\/pre>\n<h3 id=\"using-requirefailure-to-recognize-multiple-taps\">Using requireFailure to recognize multiple taps<\/h3>\n<p>Because multiple gestures can be recognized simultaneously and a gesture can be recognized based on the failure of other gestures. Multiple taps on the same element can be easily recognized on this way:<\/p>\n<pre><code>var hammer = new Hammer(el, {});\r\n\r\nvar tap = new Hammer.Tap();\r\nvar doubleTap = new Hammer.Tap({event: 'doubleTap', taps: 2 });\r\nvar tripleTap = new Hammer.Tap({event: 'tripleTap', taps: 3 });\r\n\r\nhammer.add([tripleTap, doubleTap, tap]);\r\n\r\ntripleTap.recognizeWith([doubleTap, tap]);\r\ndoubleTap.recognizeWith(tap);\r\n\r\ndoubleTap.requireFailure(tripleTap);\r\ntap.requireFailure([tripleTap, doubleTap]);\r\n<\/code><\/pre>\n<p>When a tap gesture requires a failure to be recognized, its recognizer will wait a short period to check that the other gesture has been failed. In this case, you should not assume that its tap gesture event will be fired immediately.<\/p>\n<div>\n<div>\n<h1 id=\"tips-n-tricks\">Tips &#8216;n Tricks<\/h1>\n<h3 id=\"try-to-avoid-vertical-pan-swipe\">Try to avoid vertical pan\/swipe<\/h3>\n<p>Vertical panning is used to scroll your page, and some (older) browsers don&#8217;t send events so Hammer isn&#8217;t able to recognize these gestures. An option would be to provide an alternative way to do the same action.<\/p>\n<h3 id=\"test-on-a-real-device\">Test on a real device<\/h3>\n<p>Sometimes Hammer just needs some fine-tuning, like the swipe velocity or some other thresholds. Also, for better performance on slower devices your should try to keep you callbacks as simple as possible.<\/p>\n<h3 id=\"remove-tap-highlight-on-windows-phone\">Remove tap highlight on Windows Phone<\/h3>\n<p>IE10 and IE11 on Windows Phone have a small tap highlight when you tap an element. Adding this meta tag removes this.<\/p>\n<pre><code>&lt;meta name=\"msapplication-tap-highlight\" content=\"no\" \/&gt;\r\n<\/code><\/pre>\n<h3 id=\"-i-can-t-select-my-text-anymore-\">&#8220;I can&#8217;t select my text anymore!&#8221;<\/h3>\n<p>Hammer is setting a property to improve the UX of the panning on desktop. Regularly, the desktop browser would select the text while you drag over the page. The <code>user-select<\/code> css property disables this.<\/p>\n<p>If you care about the text-selection and not so much about the desktop experience, you can simply remove this option from the defaults. Make sure you do this before creating an instance.<\/p>\n<pre><code>delete Hammer.defaults.cssProps.userSelect;\r\n\r\n\r\n<\/code><\/pre>\n<div>\n<h1 id=\"browser-device-support\">Browser\/device support<\/h1>\n<p>Don&#8217;t worry if your browser or OS isn&#8217;t listed, it might work anyway! Internet Explorer 8 and older aren&#8217;t supported.<\/p>\n<p>Browsers that have native support for touch-action might have an improved experience then the browsers that don&#8217;t.<\/p>\n<table>\n<thead>\n<tr>\n<th>Browser<\/th>\n<th>Pan<\/th>\n<th>Pinch<\/th>\n<th>Press<\/th>\n<th>Rotate<\/th>\n<th>Swipe<\/th>\n<th>Tap<\/th>\n<th>Multi-user<\/th>\n<th>Touch-action<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Windows Phone 8 &#8211; IE10<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<\/tr>\n<tr>\n<td>Android 2.3 &#8211; browser<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>Android 2.3 &#8211; FireFox<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>Android 4.x &#8211; browser<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>Android 4.4 &#8211; browser<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<\/tr>\n<tr>\n<td>Android 4 &#8211; Chrome<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<\/tr>\n<tr>\n<td>Android 4 &#8211; Opera<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>?<\/td>\n<\/tr>\n<tr>\n<td>Android 4 &#8211; FireFox<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>Android 4 w\/ mouse<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>n\/a<\/td>\n<\/tr>\n<tr>\n<td>iOS 6<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>iOS 7<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>BlackBerry 10<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>?<\/td>\n<td>?<\/td>\n<\/tr>\n<tr>\n<td>FireFox OS (simulator)<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>?<\/td>\n<td>?<\/td>\n<\/tr>\n<tr>\n<td>Desktop &#8211; IE11<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<\/tr>\n<tr>\n<td>Desktop &#8211; IE10<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<\/tr>\n<tr>\n<td>Desktop &#8211; IE9<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>Desktop &#8211; Chrome<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<\/tr>\n<tr>\n<td>Desktop &#8211; Firefox<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>Desktop &#8211; Opera<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>?<\/td>\n<\/tr>\n<tr>\n<td>Chromebook<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>?<\/td>\n<\/tr>\n<tr>\n<td>Windows 8 \/w pen<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>n\/a<\/td>\n<\/tr>\n<tr>\n<td>Windows 8 \/w touch<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>n\/a<\/td>\n<\/tr>\n<tr>\n<td>Windows 8 \/w mouse<\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td><\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>n\/a<\/td>\n<\/tr>\n<tr>\n<td>Windows 8 \/w mixed<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>\u2665<\/td>\n<td>n\/a<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<hr \/>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>All about hammer.js a start to touch gestures and multitouch Hammer is a open-source JavaScript Library for adding touch gestures support that can recognize gestures [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0},"categories":[7,6],"tags":[],"_links":{"self":[{"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/posts\/701"}],"collection":[{"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/comments?post=701"}],"version-history":[{"count":2,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/posts\/701\/revisions"}],"predecessor-version":[{"id":704,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/posts\/701\/revisions\/704"}],"wp:attachment":[{"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/media?parent=701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/categories?post=701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.prasadk.com\/my-press\/wp-json\/wp\/v2\/tags?post=701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}