Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
How to prevent collapse of the elements when the direction of the touchmove? - bug-code.com Q&A

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

0 like 0 dislike
41 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 | 41 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
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers

0 comments

12.3k users

24,788 questions
46,220 answers
0 comments
12,337 users