确定触摸移动的垂直方向 [英] Determine vertical direction of a touchmove
本文介绍了确定触摸移动的垂直方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为平板电脑实现一个触摸监听器来触发一些动作,具体取决于触摸是向上还是向下移动.
i'm trying to implement a touch listener for tablets to trigger some actions depending whether it touchmoved upwards or downwards.
我尝试了本地监听器:
($document).bind('touchmove', function (e)
{
alert("it worked but i don't know the direction");
});
但我不知道如何确定方向.
But i don't know how to determine the direction.
这可能吗?
或者我是否需要使用touchstart/touchend,如果我需要这个,我可以在触摸移动停止之前确定方向吗?
Or do i need to use touchstart/touchend, if I need this can I determine the direction before the touch movement stops?
如果我只能使用外部库来做到这一点,最好的方法是什么?
If I can only do this with an external library, what's the best one?
谢谢.
推荐答案
我在 Ipad 中遇到了一些问题,通过两个事件解决了
I had some issues in Ipad and solved it with two events
var ts;
$(document).bind('touchstart', function (e){
ts = e.originalEvent.touches[0].clientY;
});
$(document).bind('touchend', function (e){
var te = e.originalEvent.changedTouches[0].clientY;
if(ts > te+5){
slide_down();
}else if(ts < te-5){
slide_up();
}
});
这篇关于确定触摸移动的垂直方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文