У меня были проблемы с принятым ответ здесь, потому что ударяя не был обнаружен, когда происхождение и цель прикосновением не были одинаковыми.
Здесь может быть проще ответ, где я непосредственно переопределить событие JQuery handleSwipe (на основе jquery.mobile-1.4.5) и добавить его с вертикальным движением, называется вверх и вниз:
(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);
это точно что я хочу, и это сработало для меня. – Muath
Как настроить прослушиватель для события swipeupdown и выполнить различные задачи для события swipeup и swipedown? –
@SantoshGhimire, вы можете использовать '$ ('mySelector'). On ('swipeup', function() {});' и '$ ('mySelector'). On ('swipedown', function() {}) ; ' – Turnerj