Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Example</h2> <p>Working example: <a href="http://jsfiddle.net/Gajotres/K69AJ/">http://jsfiddle.net/Gajotres/K69AJ/</a></p> <h2>Code</h2> <p>Javascript code:</p> <pre><code>var gnStartX = 0; var gnStartY = 0; var gnEndX = 0; var gnEndY = 0; $(document).on('vmousedown', function(event){ gnStartX = event.pageX; gnStartY = event.pageY; event.preventDefault(); }); $(document).on('vmouseup', function(event){ gnEndX = event.pageX; gnEndY = event.pageY; var distance = Math.ceil(nthroot(Math.pow((gnEndX - gnStartX),2) + Math.pow((gnEndY - gnStartY),2), 2)); if(Math.abs(gnEndX - gnStartX) &gt; Math.abs(gnEndY - gnStartY)) { if(gnEndX &gt; gnStartX) { alert("Swipe Right - Distance " + distance + 'px'); } else { alert("Swipe Left - Distance " + distance + 'px'); } } else { if(gnEndY &gt; gnStartY) { alert("Swipe Bottom - Distance " + distance + 'px'); } else { alert("Swipe Top - Distance " + distance + 'px'); } } event.preventDefault(); }); function nthroot(x, n) { try { var negate = n % 2 == 1 &amp;&amp; x &lt; 0; if(negate) x = -x; var possible = Math.pow(x, 1 / n); n = Math.pow(possible, n); if(Math.abs(x - n) &lt; 1 &amp;&amp; (x &gt; 0 == n &gt; 0)) return negate ? -possible : possible; } catch(e){} } </code></pre> <p>This is my example that will give you direction and distance. Events used is <strong><code>vmousedown</code></strong> and <strong><code>vmouseup</code></strong>. They are jQuery Mobile events that are used to bridge touch events between desktop and mobile browsers, basically it will work on any platform. If you want only mobile platform then change <strong><code>vmousedown</code></strong> -> <strong><code>touchstart</code></strong> and <strong><code>vmouseup</code></strong> -> <strong><code>touchend</code></strong>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload