title: jQuery touchSwipe content scroll function
body: <p>I am using jQuery and the touchSwipe plugin to scroll content up and down. I am having some math related issues and wanted to see if the community could quickly help me figure this out.</p>
  
  <p>The touchSwipe "distance" variable returns only positive values starting from zero so the issue comes in to play when the user swipes UP and then decides to swipe DOWN, because the distance values change from ex:(0 initial, 15up, 32up, 20up, 5up, 10down, 40down). I have created 4 if statements to catch all of these situations. How do I handle the "direction change" if statements?</p>
  
  <p>touchSwipe: <a href="http://labs.skinkers.com/touchSwipe/" rel="nofollow">http://labs.skinkers.com/touchSwipe/</a></p>
  
  <p>The swipe up and down function:</p>
  
  <pre><code>var _scrolling=false;
  var _prev=0;
  $("#list").swipe({
    swipeStatus:function(event, phase, direction, distance, fingerCount) {
      if(phase=="end"){return false;}
      if(phase=="move" &amp;&amp; !_scrolling) {
        var t = parseInt($("#list").css("top").split('px')[0]);
        var s = 0;
        if(direction=="up" &amp;&amp; (distance-_prev) &gt; 0){
           //still moving up
           s = t-(distance-_prev);
           _prev=distance;
         } else if(direction=="up" &amp;&amp; (distance-_prev) &lt; 0){
            //direction change - moving down    
         } else if(direction=="down" &amp;&amp; (distance-_prev) &gt; 0){
           //still moving down
            s = t+(distance-_prev);
           _prev=distance;
         } else if(direction=="down" &amp;&amp; (distance-_prev) &lt; 0){
            //direction change - moving up
         }
         _scrolling=true;
         $("#list").animate({ top:s }, 70, function() {_scrolling=false;});   
     }&lt;!--if end--&gt;
    }&lt;!--swipeStatus end--&gt;
  });
  </code></pre>