Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only swipeone is working with jGestures

I'm trying to implement touch evens with jGestures. swipeone works fine but anything else (swipeleft, swiperight etc) is not firing.

<div id="wrap" style="height:500px; width:500px; background: blue;">

    </div>
    <script type="text/javascript">
        $('#wrap').bind('swipeleft', function(){
            alert("test");
        });
    </script>

This is just a test page I did. It was actually working at one point in my main project but seemed to have stopped for no reason at all, not even when I reverted to an older version. I've tried a different version of jGestures with no luck.

like image 597
Jasard Avatar asked Feb 23 '12 12:02

Jasard


People also ask

Why my phone gestures are not working?

Solution 1 – Check settings By default, most OEMs will stick to a 3-button navigation at the bottom. So, you'll need to enable gestures before using them. On some devices, you have a choice between the Android 9 Pie gestures that come with the pill at the bottom and full-screen gestures that come with Android 10.

How do I enable gestures on Android?

You can easily enable or disable the 'Gesture' settings. Just navigate to Settings > System > Gestures . Here, you can enable or disable a number of Gesture settings.


3 Answers

SwipeLeft, SwipeRight, -Up and -Down are kind of poorly implemented. They are only triggered if you stay EXACTLY on the axis where you started the touch event. For example, SwipeRight will only work if your finger moves from (X,Y) (120, 0) to (250, 0).

If the Y-Coordinates from Start- and Endpoint differ, it's not gonna work.

jGestures.js (ca. line 1095) should better look something like this (readable):

/**
 * U Up, LU LeftUp, RU RightUp, etc.
 * 
 *  \U|U/
 * LU\|/RU
 *L---+---R
 * LD/|\RD
 *  /D|D\
 *
 */
if ( _bHasTouches && _bHasMoved === true && _bHasSwipeGesture===true) {
    _bIsSwipe = true;
    var deltaX = _oDetails.delta[0].lastX;
    var deltaY = _oDetails.delta[0].lastY;
    var hor = ver = '';
    if (deltaX > 0) { // right
        hor = 'right';
        if (deltaY > 0) {
            ver = 'down'
        } else {
            ver = 'up';
        }

        if (Math.abs(deltaY) < deltaX * 0.3) {
            ver = '';
        } else if (Math.abs(deltaY) >= deltaX * 2.2) {
            hor = '';
        }
    } else { // left
        hor = 'left';
        if (deltaY > 0) {
            ver = 'down'
        } else {
            ver = 'up';
        }

        if (Math.abs(deltaY) < Math.abs(deltaX) * 0.3) {
            ver = '';
        } else if (Math.abs(deltaY) > Math.abs(deltaX) * 2.2) {
            hor = '';
        }
    }
    // (_oDetails.delta[0].lastX < 0) -> 'left'
    // (_oDetails.delta[0].lastY > 0) -> 'down'
    // (_oDetails.delta[0].lastY < 0) -> 'up'
    // alert('function swipe_' + hor + '_' + ver);

    _oDetails.type = ['swipe', hor, ver].join('');
    _$element.triggerHandler(_oDetails.type, _oDetails);
}
like image 177
Who Avatar answered Oct 04 '22 19:10

Who


try this:

$('#wrap').bind('swipeone', function (event, obj) {
   var direction=obj.description.split(":")[2]
   if(direction=="left"){
        doSomething();
   }
});
like image 27
William El-Turk Avatar answered Oct 04 '22 18:10

William El-Turk


This is already answered here:

stackoverflow about jGesture swipe events

The trick is:

… .bind('swipeone swiperight', … 

You have to bind it to both events. only swiperight won't work. took me 3 hrs to figure that out :D

Best, Rico

like image 33
Rico Neitzel Avatar answered Oct 04 '22 19:10

Rico Neitzel