I’m trying to save the mouse Y coordinates to the variable startPosition ONLY every 100ms while .mousemove is active, while the mouse button is held(mousedown), my code isn’t working for me, i’m assuming it’s wrong? Can someone help me figure this out?
$(document).mousemove( function (e) {
gesturesY = parseInt(e.pageY, 10);
startPosition = setInterval(gesturesY, 100);
});
EDIT:
I think this might be a whole new question? Sorry for any confusion, below is clarification for my jumbled mess of a question.
Here we go:
http://jsfiddle.net/nicktheandroid/PCgFK/1/
This JSfiddle allows you to grab the page in the scrollbox and fling it up or down, like a touchscreen phone. Right now, if you grab the page(in the scrollbox area) and move your mouse up(causing the page to scroll down), then release the mouse button, the velocity will kick in and it will jump the page a little. It’s there for when you actually grab the page and flick it up or down to scroll the page, it makes it come to a nice slow and steady stop. If the person doesn’t flick, but instead just drags the page and then holds the mouse steady and releases the mouse button, it jumps, like I stated above. I’m trying to get rid of that jump when the person grabs and drags the page, then while the mouse is still, releases the mouse button.
I thought that by updating the startPosition every 100ms or so, that it would eliminate that jump but still keep the velocity slow down from flicking the page up or down. I’m pretty close to being done with this, but there’s still the problem that i just stated. Someone else helped me out with adding the velocity, and in the script there’s a variable called velocityCheckWait that I think is doing the opposite of what I wanted it to do.
Sorry for any confusion, and thank you to anyone who could dedicate any time to helping me out.
There isn’t anything to really do what you want; the best way to emulate this is the code below:
This updates the mouse position constantly, but only updates it to the variable you want every 100ms (in the meantime, its updating the other variable
currentPosition.If you’re only wanting to update the position every 100ms due to performance worries, firstly, I’d double check you aren’t underestimating the power of computers these days. If it is a valid concern however, the following code will help you:
In here, startPosition is been updated all the time, but you’re only executing your interval every 100ms.