title: Detect dragup or drag down
body: <p>I have written the following:</p>
  
  <pre><code>var motion;
  var yPosStart = 0;
  var yPosEnd = 0;
  var lastDrag;
  var mouseDown = false;
  
  function drag(){
      $("*")
      .mousedown(function() {
          $(window).unbind('mousedown');
          if( mouseDown === false ) {
              mouseDown = true;
              $(window).mousemove(function(e) {
                  if( yPosStart == 0 ) {
                      yPosStart = e.pageY;
                  }else{
                      yPosEnd = e.pageY;  
                  }
              });
          }
      })
      .mouseup(function() {
          mouseDown = false;
          lastDrag = ( yPosStart &lt; yPosEnd ? 'down' : 'up' );
          yPosStart = 0;
          yPosEnd = 0;
          alert( lastDrag );
          $(window).bind('mousedown');
      });
  }
  </code></pre>
  
  <p>I am trying to detect a drag down or drag up, but I also want to know how far. This does not seem to be working correctly and also alerts multiple times in some instances. Can anyone advise me where I am going wrong please.</p>