Get the element under a touchend

半城伤御伤魂 提交于 2019-12-19 12:51:30

问题


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.


回答1:


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/



来源:https://stackoverflow.com/questions/12596121/get-the-element-under-a-touchend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!