Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wrote my own touch handler events.maybe this helps you</p> <p>it checks for:</p> <p>fast click : 'fc'</p> <p>swipe left : 'swl'</p> <p>swipe right : 'swr'</p> <p>swipe up : 'swu'</p> <p>swipe down : 'swd'</p> <p>each check initializes it's correspondent event.but you can scroll and do whatever else you do normally. you just have some new events. </p> <p>you need swl swr, I aslo suggest to use fc (fastclick) for click events... it's much faster than normal click.</p> <pre><code>window.onload=function(){ (function(d){ var ce=function(e,n){var a=document.createEvent("CustomEvent");a.initCustomEvent(n,true,true,e.target);e.target.dispatchEvent(a);a=null;return false}, nm=true,sp={x:0,y:0},ep={x:0,y:0}, touch={ touchstart:function(e){sp={x:e.touches[0].pageX,y:e.touches[0].pageY}}, touchmove:function(e){nm=false;ep={x:e.touches[0].pageX,y:e.touches[0].pageY}}, touchend:function(e){if(nm){ce(e,'fc')}else{var x=ep.x-sp.x,xr=Math.abs(x),y=ep.y-sp.y,yr=Math.abs(y);if(Math.max(xr,yr)&gt;20){ce(e,(xr&gt;yr?(x&lt;0?'swl':'swr'):(y&lt;0?'swu':'swd')))}};nm=true}, touchcancel:function(e){nm=false} }; for(var a in touch){d.addEventListener(a,touch[a],false);} })(document); //EXAMPLE OF USE var h=function(e){console.log(e.type,e)}; document.body.addEventListener('fc',h,false);// 0-50ms vs 500ms with normal click document.body.addEventListener('swl',h,false); document.body.addEventListener('swr',h,false); document.body.addEventListener('swu',h,false); document.body.addEventListener('swd',h,false); } </code></pre> <p>in this case h is my handler for every type of event and i add the handlers to the body.</p> <p>for what i understand your question you just have to write</p> <pre><code>YOURELEMENT.addEventListener('swr',YOURSWIPERIGHTFUNCTION,false); YOURELEMENT.addEventListener('swl',YOURSWIPELEFTFUNCTION,false); </code></pre> <p>to handle multiple elements and the same function... just add one handler.</p> <p>so if you have</p> <pre><code>&lt;ul id="ul"&gt;&lt;li&gt;1&lt;/li&gt;&lt;li&gt;2&lt;/li&gt;&lt;li&gt;3&lt;/li&gt;&lt;/ul&gt; </code></pre> <p>you do:</p> <pre><code>var deleteli=function(e){ var li=e.target; console.log('deleting '+li.textContent); } document.getElementById('ul').addEventListener('swl',deleteli,false); </code></pre> <p>same for fc &amp; swr</p> <p>there is a bug in ios: don't use alert() .. it will execute 2 times.</p>
    singulars
    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