Recognize diagonal gestures (swipe axis) with Hammer.js
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 to share