I\'m trying to make event on swiping up and down instead of left and right
i have this roll as image shows:
I had Problems with the accepted answer here, because swiping wasn't detected when origin and target of the swipe were not the same.
Here maybe an easier answer, where i directly override the jquery handleSwipe event (based on jquery.mobile-1.4.5) and append it with a vertical swipe, called up and down:
(function( $, window, undefined ) {
//custom handleSwipe with swiperight, swipeleft, swipeup, swipedown
$.event.special.swipe.handleSwipe = function( start, stop, thisObject, origTarget ) {
if ( stop.time - start.time < $.event.special.swipe.durationThreshold ) {
var horSwipe = Math.abs( start.coords[0] - stop.coords[0] ) > $.event.special.swipe.horizontalDistanceThreshold;
var verSwipe = Math.abs( start.coords[1] - stop.coords[1] ) > $.event.special.swipe.verticalDistanceThreshold;
if( horSwipe != verSwipe ) {
var direction;
if(horSwipe)
direction = start.coords[0] > stop.coords[0] ? "swipeleft" : "swiperight";
else
direction = start.coords[1] > stop.coords[1] ? "swipeup" : "swipedown";
$.event.trigger($.Event( "swipe", { target: origTarget, swipestart: start, swipestop: stop }), undefined, thisObject);
$.event.trigger($.Event( direction, { target: origTarget, swipestart: start, swipestop: stop }), undefined, thisObject);
return true;
}
return false;
}
return false;
}
//do binding
$.each({
swipeup: "swipe.up",
swipedown: "swipe.down"
}, function( event, sourceEvent ) {
$.event.special[ event ] = {
setup: function() {
$( this ).bind( sourceEvent, $.noop );
},
teardown: function() {
$( this ).unbind( sourceEvent );
}
};
});
})( jQuery, this );