Bind the handler on the touchmove event: http://jsfiddle.net/Y4fHD/1/var endCoords = {};$(document.body).bind("touchmove", function(event) { endCoords = event.originalEvent.targetTouches[0];});然后使用变量endCoords确定最后一次触摸And then use the variable endCoords to determinate the last touch$(document.body).bind("touchend", function(event) { $('p').text("Your end coords is: x: " + endCoords.pageX + ", y: " + endCoords.pageY);});确定尝试点击您的设备!然后错误仍然会发生:为什么?因为你没有动弹.Ok try to just tap your device! Then the error still will ocure: Why? Because you havn't moved your touch.如果我们都已经准备好在touchstart中定义endCoords变量,那么我们就在这里: http://jsfiddle.net/Y4fHD /2/ If we all ready in the touchstart defines the endCoords variable we are there: http://jsfiddle.net/Y4fHD/2/var endCoords = {};$(document.body).bind("touchstart touchmove", function(event) { endCoords = event.originalEvent.targetTouches[0];});然后使用变量endCoords确定最后一次触摸And then use the variable endCoords to determinate the last touch$(document.body).bind("touchend", function(event) { $('p').text("Your end coords is: x: " + endCoords.pageX + ", y: " + endCoords.pageY);});现在尝试点击您的设备!Now try to tap your device!最后的一些注意事项是:制作变量:startCoords和endCoords,然后在touchend事件中使用它们: http ://jsfiddle.net/Y4fHD/3/ Some final notes will be: Make to variables: startCoords and endCoords then use these in the touchend event: http://jsfiddle.net/Y4fHD/3/var startCoords = {}, endCoords = {};$(document.body).bind("touchstart", function(event) { startCoords = endCoords = event.originalEvent.targetTouches[0];});$(document.body).bind("touchmove", function(event) { endCoords = event.originalEvent.targetTouches[0];});$(document.body).bind("touchend", function(event) { $('p').text("Your touch on the axis: " + Math.abs(startCoords.pageX-endCoords.pageX) + "x, " + Math.abs(startCoords.pageY-endCoords.pageY) + "y");});注意:以上示例均未经过测试,希望它能正常工作!Math.abs给我一个数字的绝对值,例如:-5变成5 Note:None of the above examples are tested, hopes it works!Math.abs gives me the absolute value of a number eg: -5 becomes 5 这篇关于jQuery(滑动与触摸)pageX和pageY始终返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-16 02:08