Mua*_*ath 27 javascript css jquery html5 jquery-mobile
我试图上下左右而不是左右滑动
我有这个卷,如图所示:
我可以使用箭头图标处理事件(onClick()),但我想添加向上滑动事件,当添加滑动事件时,它在左侧工作我希望它向下,因为图像显示任何帮助?
Tay*_* Q. 51
jQuery Mobile本身为我们提供了捕获swipeleft和swiperight的能力.然而,它并没有为我们提供swipeup和swipeown开箱即用.通过调整jQuery团队为swipeleft和swiperight所做的工作,我们能够以相同的方式创建和捕获这些事件.请参阅以下代码以实现swipeup和swipeown:
(function() {
var supportTouch = $.support.touch,
scrollEvent = "touchmove scroll",
touchStartEvent = supportTouch ? "touchstart" : "mousedown",
touchStopEvent = supportTouch ? "touchend" : "mouseup",
touchMoveEvent = supportTouch ? "touchmove" : "mousemove";
$.event.special.swipeupdown = {
setup: function() {
var thisObject = this;
var $this = $(thisObject);
$this.bind(touchStartEvent, function(event) {
var data = event.originalEvent.touches ?
event.originalEvent.touches[ 0 ] :
event,
start = {
time: (new Date).getTime(),
coords: [ data.pageX, data.pageY ],
origin: $(event.target)
},
stop;
function moveHandler(event) {
if (!start) {
return;
}
var data = event.originalEvent.touches ?
event.originalEvent.touches[ 0 ] :
event;
stop = {
time: (new Date).getTime(),
coords: [ data.pageX, data.pageY ]
};
// prevent scrolling
if (Math.abs(start.coords[1] - stop.coords[1]) > 10) {
event.preventDefault();
}
}
$this
.bind(touchMoveEvent, moveHandler)
.one(touchStopEvent, function(event) {
$this.unbind(touchMoveEvent, moveHandler);
if (start && stop) {
if (stop.time - start.time < 1000 &&
Math.abs(start.coords[1] - stop.coords[1]) > 30 &&
Math.abs(start.coords[0] - stop.coords[0]) < 75) {
start.origin
.trigger("swipeupdown")
.trigger(start.coords[1] > stop.coords[1] ? "swipeup" : "swipedown");
}
}
start = stop = undefined;
});
});
}
};
$.each({
swipedown: "swipeupdown",
swipeup: "swipeupdown"
}, function(event, sourceEvent){
$.event.special[event] = {
setup: function(){
$(this).bind(sourceEvent, $.noop);
}
};
});
})();
Run Code Online (Sandbox Code Playgroud)
这是Blackdynamo的答案
归档时间: |
|
查看次数: |
26235 次 |
最近记录: |