I am making a slider that, moves to left when it is swiped to left, and, moves to right when swiped to right. Her is what I've acheived till now https://jsfiddle.net/6ze720f7/ . Although I can now just set position left: 0 when left is displayed and position left: 446 px when Right is displayed.
The code that takes care of the direction is:
center.onmousemove = function(Dmove) {
if (Dmove.pageX < oldx) {
direction = "left"
} else if (Dmove.pageX > oldx) {
direction = "right"
}
oldx = Dmove.pageX;
}
What I am worried about is that the difference between oldx and Dmove.pageX is very very small, more precisely the amount of time taken in the execution of a few lines of javscript code. So if the div is swiped to left for 1 second but at the end it is moved to right, by mistake, for a few milliseconds then the div will be swiped to right. The solution I thought is to use 10ms older value of oldx.
- Is it possible to find 10 millisecond older value than present of
Dmove.pageX? - Is it possible to give a synchronus delay of 10 millsecond after the statement
oldx = Dmove.pageX;? - Is it possible to use
setInterval()function in such a way that it would set the valueoldxafter every 10 second? This could be a little problamatic because the difference betweenoldxand present value ofDmove.pageXcould be taken anything between 0 to 10ms when themouseupevent happens.
