admin管理员组文章数量:1425695
I'm trying to bind an event to the touchstart, touchmove, and touchend properties that will track the location of the touch. Here's my code:
$('#container').bind('touchstart touchmove touchend', function (event) { updateFinger(event); });
And the update finger function:
var updateFinger = function(e)
{
e.preventDefault();
fingerX = e.data.x1;
fingerY = e.data.y1;
alert(fingerX + ' ' + fingerY);
}
I know the function is called, but from what I can tell, e.data.x1 and e.data.y1 don't exist (As well as .x). I'm using the code in the documentation, can anyone help me out with this?
EDIT: I fixed the problem, it turns out I was using the wrong code.
Instead of
e.data.x1
You need to use
e.touches[0].pageX
I'm trying to bind an event to the touchstart, touchmove, and touchend properties that will track the location of the touch. Here's my code:
$('#container').bind('touchstart touchmove touchend', function (event) { updateFinger(event); });
And the update finger function:
var updateFinger = function(e)
{
e.preventDefault();
fingerX = e.data.x1;
fingerY = e.data.y1;
alert(fingerX + ' ' + fingerY);
}
I know the function is called, but from what I can tell, e.data.x1 and e.data.y1 don't exist (As well as .x). I'm using the code in the documentation, can anyone help me out with this?
EDIT: I fixed the problem, it turns out I was using the wrong code.
Instead of
e.data.x1
You need to use
e.touches[0].pageX
Share
Improve this question
edited Aug 20, 2012 at 3:20
wprl
25.5k11 gold badges57 silver badges70 bronze badges
asked Jan 13, 2012 at 15:02
CSturgessCSturgess
1,5572 gold badges13 silver badges29 bronze badges
1
- 1 That's great. Could you create an answer for that and mark it as accepted. This way, your question will move out of the "unanswered" lists. – swatkins Commented Jan 16, 2012 at 20:36
1 Answer
Reset to default 7Instead of
e.data.x1
You need to use
e.touches[0].pageX
本文标签: javascriptHow do you bind a touch function with Zepto properlyStack Overflow
版权声明:本文标题:javascript - How do you bind a touch function with Zepto properly? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745394689a2656759.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论