1

我怎样才能获得速度(velocityX),我的手指在 HTML5 中从一个点移动到另一个点。我在 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_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);

其实我想把这行Android改成Html5

if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)

如果有任何请指导 HTML5 中的单点触控功能,如 Android onSingleTapUp

4

0 回答 0