UNPKG

hammerjs

Version:

A javascript library for multi-touch gestures

33 lines (32 loc) 993 B
/** * Swipe * triggers swipe events when the end velocity is above the threshold * for best usage, set prevent_default (on the drag gesture) to true * @events swipe, swipeleft, swiperight, swipeup, swipedown */ Hammer.gestures.Swipe = { name : 'swipe', index : 40, defaults: { swipe_min_touches: 1, swipe_max_touches: 1, swipe_velocity : 0.7 }, handler : function swipeGesture(ev, inst) { if(ev.eventType == EVENT_END) { // max touches if(ev.touches.length < inst.options.swipe_min_touches || ev.touches.length > inst.options.swipe_max_touches) { return; } // when the distance we moved is too small we skip this gesture // or we can be already in dragging if(ev.velocityX > inst.options.swipe_velocity || ev.velocityY > inst.options.swipe_velocity) { // trigger swipe events inst.trigger(this.name, ev); inst.trigger(this.name + ev.direction, ev); } } } };