How to prevent collapse of the elements when the direction of the touchmove?

0 like 0 dislike
27 views
All kind time of day!
There is a standard function of detecting the touch and determining the direction of movement of the several elements during touchmove in javascript
elements.addEventListener('touchstart', function() {
initial = e.originalEvent.touches[0].clientX;
});
elements.addEventListener('touchmove', function(e) {
var touch_offset = e.originalEvent.changedTouches[0].clientX;
if (initial > touch_offset) {
move_left();
} else {
move_right();
}
});

There is also an array of coordinates for elements when you change their id within the function move_left(); move_right();
When fixing the first touchstart, touchmove, and determining the direction, the elements return to normal simultaneously move to the corresponding coordinates of the array (due to the dynamic changing id and associated styles within the absolute position). However, if at the moment of movement elements, for example, to the left to change the direction of movement of the finger on the screen to the right, the elements have not yet reached the coordinates to the left direction, trying to move to the right, twitching and randomly "collapse" to the center div. How to disable the function to the right, if not completed, the option "left" or in some other way?
asked by | 27 views

1 Answer

0 like 0 dislike
var touch_direction = "left"; ..... if(initial > touch_offset) { touch_direction = "left"; move_left(); } else { touch_direction = "right"; move_right(); } ... function move_left(){ for(....) { if(touch_direction != 'left') { return; } } }

well, move_right for example
answered by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
24,509 questions
45,932 answers
0 comments
346 users