Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the element under a touchend

As the touchend event is bind to the element where the touchstart is fired, how can I get the element at the position where the finger leaves, when this is outside of the element where the event was binded to.

like image 540
Andreas Köberle Avatar asked Sep 26 '12 06:09

Andreas Köberle


1 Answers

You could use the document.elementFromPoint method, passing it the coordinates of the event:

$('#element').on("touchend",function(event){
    var endTarget = document.elementFromPoint(
        event.originalEvent.touches[0].pageX,
        event.originalEvent.touches[0].pageY
    );
});

EDIT: Found some good article about getting elements at specific coordinates. http://www.zehnet.de/2010/11/19/document-elementfrompoint-a-jquery-solution/

like image 193
Armel Larcier Avatar answered Sep 30 '22 18:09

Armel Larcier