Android 在HTML5中获得触摸移动的速度
在HTML5中,我如何获得手指从一点移动到另一点的速度(velocityX)。我在android中使用过速度(velocityX)。就像这样Android 在HTML5中获得触摸移动的速度,android,html,Android,Html,在HTML5中,我如何获得手指从一点移动到另一点的速度(velocityX)。我在android中使用过速度(velocityX)。就像这样 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){ private static final int SWIPE_MIN_DISTANCE = 30; private static final int SWIPE_MAX
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY){
private static final int SWIPE_MIN_DISTANCE = 30;
private static final int SWIPE_MAX_OFF_PATH = 200;
private static final int SWIPE_THRESHOLD_VELOCITY = 400;
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
startActivity( new Intent( this, x.class ) );
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
// Toast.makeText(getApplicationContext(), "Right Swipe", Toast.LENGTH_SHORT).show();
startActivity( new Intent( this , aasas.class) );
}
else if(e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
} else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
}
} catch (Exception e) {
// nothing
}
return true;
}
我想在html5中实现同样的功能,但我无法获得velocityX,我的html5代码就是这样
this.downX = null;
this.upX = null;
document.body.addEventListener('touchstart', function(event) {
event.preventDefault();
console.log("movvv");
this.downX = event.touches[0].pageX;
}, true);
document.body.addEventListener('touchmove', function(event) {
event.preventDefault();
this.upX = event.touches[0].pageX;
}, true);
document.body.addEventListener('touchend', function(event) {
event.preventDefault();
if ((this.downX - this.upX) > 50) {
console.log("goooo");
}
if ((this.upX - this.downX) > 50) {
}
}, true);
实际上,我想把安卓的这一行改成Html5
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
如果有任何plz指南,HTML5中是否有与Android onSingleTapUp类似的单触功能,[这][1]帮助我解决了问题[1]: