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:
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.
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.