Answer the question
In order to leave comments, you need to log in
The code from the example from the article from Habr does not work, what is the error, or is it just me?
The code from the example from habr tyrk :
var touchstartX = 0;
var touchstartY = 0;
var touchendX = 0;
var touchendY = 0;
var gesuredZone = document.getElementById('gesuredZone');
gesuredZone.addEventListener('touchstart', function(event) {
touchstartX = event.screenX;
touchstartY = event.screenY;
}, false);
gesuredZone.addEventListener('touchend', function(event) {
touchendX = event.screenX;
touchendY = event.screenY;
handleGesure();
}, false);
function handleGesure() {
var swiped = 'swiped: ';
if (touchendX < touchstartX) {
alert(swiped + 'left!');
}
if (touchendX > touchstartX) {
alert(swiped + 'right!');
}
if (touchendY < touchstartY) {
alert(swiped + 'down!');
}
if (touchendY > touchstartY) {
alert(swiped + 'left!');
}
if (touchendY == touchstartY) {
alert('tap!');
}
}
Answer the question
In order to leave comments, you need to log in
Stepped on the same rake. Mouse works great, touch doesn't. Began to step-by-step display alert'om values on the screen. The touchstart and touchend events themselves work. Then I tried to output event.screenX and got Undefined . It turns out that the event.screenX construct is not quite what we need for Touch . I rummaged through various articles. Found three properties: touches , targetTouches , changedTouches . I did this:
for touchstart :
for touchend :
Well for Y respectively.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question