swiperjs怎么判断左右滑动

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swiperjs怎么判断左右滑动相关的知识,希望对你有一定的参考价值。

参考技术A 直接看官网API吧:
http://www.swiper.com.cn/api/Navigation_Buttons/2015/0308/209.html
参考技术B swiper.swipeDirection=='prev' 右滑

swiper.swipeDirection=='next' 左滑

android 判断左右滑动,上下滑动的GestureDetector简单手势检测

直接加入监听GestureDetector放在需要判断滑动手势的地方:

 1 import android.app.Activity;  
 2 import android.os.Bundle;  
 3 import android.util.Log;  
 4 import android.view.GestureDetector;  
 5 import android.view.GestureDetector.OnGestureListener;  
 6 import android.view.MotionEvent;  
 7   
 8 public class MainActivity extends Activity {  
 9     protected static final float FLIP_DISTANCE = 50;  
10     GestureDetector mDetector;  
11   
12     @Override  
13     protected void onCreate(Bundle savedInstanceState) {  
14         super.onCreate(savedInstanceState);  
15         setContentView(R.layout.activity_main);  
16   
17         mDetector = new GestureDetector(this, new OnGestureListener() {  
18   
19             @Override  
20             public boolean onSingleTapUp(MotionEvent e) {  
21                 // TODO Auto-generated method stub  
22                 return false;  
23             }  
24   
25             @Override  
26             public void onShowPress(MotionEvent e) {  
27                 // TODO Auto-generated method stub  
28   
29             }  
30   
31             @Override  
32             public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {  
33                 // TODO Auto-generated method stub  
34                 return false;  
35             }  
36   
37             @Override  
38             public void onLongPress(MotionEvent e) {  
39                 // TODO Auto-generated method stub  
40   
41             }  
42   
43             /** 
44              *  
45              * e1 The first down motion event that started the fling. e2 The 
46              * move motion event that triggered the current onFling. 
47              */  
48             @Override  
49             public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {  
50                 if (e1.getX() - e2.getX() > FLIP_DISTANCE) {  
51                     Log.i("TAG", "<--- left, left, go go go");  
52                     return true;  
53                 }  
54                 if (e2.getX() - e1.getX() > FLIP_DISTANCE) {  
55                     Log.i("TAG", "right, right, go go go --->");  //忽然觉得这个log好智障...
56                     return true;  
57                 }  
58                 if (e1.getY() - e2.getY() > FLIP_DISTANCE) {  
59                     Log.i("TAG", "向上滑...");  
60                     return true;  
61                 }  
62                 if (e2.getY() - e1.getY() > FLIP_DISTANCE) {  
63                     Log.i("TAG", "向下滑...");  
64                     return true;  
65                 }  
66   
67                 Log.d("TAG", e2.getX() + " " + e2.getY());  
68   
69                 return false;  
70             }  
71   
72             @Override  
73             public boolean onDown(MotionEvent e) {  
74                 // TODO Auto-generated method stub  
75                 return false;  
76             }  
77         });  
78     }  
79   
80     @Override  
81     public boolean onTouchEvent(MotionEvent event) {  
82         return mDetector.onTouchEvent(event);  
83     }  
84 }  

 

以上是关于swiperjs怎么判断左右滑动的主要内容,如果未能解决你的问题,请参考以下文章

jquery iscroll 怎么判断滑动方向

html5怎么实现页面左右滑动(下图区域),可以左右滑动但不需要换页

Android 左右滑动+上下滑动 怎么实现

android 判断左右滑动,上下滑动的GestureDetector简单手势检测

Appium里面怎么实现 左右滑动屏幕

1加手机怎么关闭网页左右滑动