Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
94
rated 0 times [  97] [ 3]  / answers: 1 / hits: 36174  / 11 Years ago, tue, july 30, 2013, 12:00:00

I am trying to capture touch coordinate on the touchend event but get undefined. The touchstart event works good, but same concept fails on touchend. I built this code with mousedown and mouseup and that works good.



What am I missing?



div.addEvent(touchstart, function (event) {
event.preventDefault(); // to avoid scrolling
span.innerHTML = event.page.x;
});
div.addEvent(touchend, function (event) {
span.innerHTML = event.page.x;
});


FIDDLE


More From » touch

 Answers
3

You need to store the values on touchmove and read it in touchend.



var lastMove = null;

// Save the touchstart to always have a position
div.addEvent('touchstart', function(event) {
lastMove = event;
});

// Override with touchmove, which is triggered only on move
div.addEvent('touchmove', function(event) {
lastMove = event;
});

[#76641] Monday, July 29, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marisela

Total Points: 103
Total Questions: 105
Total Answers: 102

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
;