touchmove事件event.pageY取值为undefined求好手

touchmove事件event.pageY取值为undefined求高手
本帖最后由 cf361610910 于 2014-10-14 08:32:44 编辑
$(document).ready(function(){
var isdown = false;
function start(event){
isdown = true;
}
function move(event){
if(isdown){
$('#test').append('<p>' + event.pageY + '</p>');
}
}
function end(event){
isdown = false;
}

$('#test').bind({
touchstart:start,
touchmove:move,
touchend:end,
mousedown:start,
mousemove:move,
mouseup:end
});
});


在<div id="test"></div>显示undefined,怎么才能显示为正确的值,是电脑端能正确取值,手机端为undefined
------解决思路----------------------
function move(event){
if(isdown){
console.log(event.type);
if(event.type == "mousemove"){
$('#test').append('<p>' + event.pageY + '</p>');
}else if (event.type == "touchmove"){
//你想要获取的是触点的位置?这个属性没有在event对象上面的。
//touch事件中,有三个属性是可以获取到这个pageY的,分别为touches,changedTouches,targetTouches,
//这三个都是数组,所以可以取值数组中的第一个元素,然后再取它的pageY即可。
$('#test').append('<p>' + event.touches[0].pageY + '</p>');
}
}
}


手机端和电脑端,触发的事件不同,所以保存到的位置也是不同的,可以查看一下:移动端的touch事件(三)