Recognize diagonal gestures (swipe axis) with Hammer.js

Is it possible to recognize diagonal napkins with Hammer.js?

I looked through their documentation but couldn't find anything talking about diagonal scrolling or panning etc.

+3


source to share


1 answer


An object with a lot of gesture information is passed to each Hammer.js event callback (as described here in the API docs ).

The property eventObject.angle

is what you are looking for. Its values ​​are between -180 and 180 ( 0 means RIGHT, -90 means UP, 90 means DOWN, 180 means LEFT).



So, here's how you can recognize diagonal sounds:

var hammertime = new Hammer(domElement);
hammertime.get("swipe").set({ direction: Hammer.DIRECTION_ALL });
hammertime.on("swipe", function(eventObject) {
    if(eventObject.angle < -90) {
        //UP-LEFT SWIPE...
    } else if(eventObject.angle < 0) {
        //UP-RIGHT SWIPE...
    } else if(eventObject.angle < 90) {
        //DOWN-RIGHT SWIPE...
    } else {
        //DOWN-LEFT SWIPE...
    }
});

      

+9


source







All Articles