Determining whether mouse is decrementing or incrementing

Hi,

I’m having an issue determining whether the mouse is increment or decrementing.


    _self.mousedown(function(e) {
      var initialValue = parseInt($('#value').val());
      var initialMouse = e.pageX;
      
      $('body').mousemove(function(e) {
        var currentMouse = e.pageX;
        
        if (currentMouse <= options.max && currentMouse >= options.box) {
          var currentValue = parseInt($('#value').val());
          var isIncrementing = currentMouse > initialMouse ? true : false;
          
          if (isIncrementing)
            currentValue += 1;
          else
            currentValue -= 1;
          
          
          $('#value').val(currentValue);
          _self.css({'left' : currentMouse});
        }
      });
    })

I know where the problem is:

currentMouse > initialMouse ? true : false;

As I move my mouse to the right, this returns true. When I move the mouse to the left, this still returns true; because the currentMouse value is still greater than the initialMouse value.

I know I’m somewhere near the correct answer, my eyes just hurt :sick:

Can someone lend a hand? thanks!

Just before the isIncrementing test set

initialMouse = currentValue;

that way the test is comparing to the last mouse position rather than the start mouse position.

That doesn’t seem to work. When I go to the right, it increments correctly. But when I go back to the left, it keeps incrementing, hits a midpoint and starts to decrement.

I got it to work.

The problem I seem to be having now, if I move the mouse too quickly, it doesn’t capture the correct number and doesn’t add/substract the correct amount because of that.

What can I do to slow it down internally without the user knowning about it?


    _self.mousedown(function(e) {
      var initialValue = parseInt($('#value').val());
      var initialMouse = e.pageX;
      var lastPosition = e.pageX;
      
      $('body').mousemove(function(e) {
        var currentMouse = e.pageX;
        
        if (currentMouse <= options.max && currentMouse >= options.box) {
          var currentValue = parseInt($('#value').val());
          var isIncrementing = currentMouse > lastPosition ? true : false;
          
          if (isIncrementing)
            currentValue += 1;
          else
            currentValue -= 1;
          
          $('#value').val(currentValue);
          _self.css({'left' : currentMouse});
          
          lastPosition = currentMouse;
        }
      });
    })

I got it by getting the last position and checking to see if the current mouse position was greater or lesser than.

What about adding or subtracting the difference between initial position and last position rather than adding or subtracting one.