我不能帮你带库,但我可以复制/粘贴我用什么做用jQuery轻扫。 这个例子只是一个向上和向下滑动,但很容易适应其他手势。
这是插件部分:
;(function($) {
$.fn.tactile = function(swipe) {
return this.each(function() {
var $this = $(document),
isTouching = false,
debut; // means start in french
$this.on('touchstart', debutGeste);
function debutGeste() { // means start of gesture
if (event.touches.length == 1) {
debut = event.touches[0].pageY;
isTouching = true;
$this.on('touchmove', geste);
}
}
function finGeste() { // means end of gesture
$this.off('touchmove');
isTouching = false;
debut = null;
}
function geste() { // geste means gesture
if(isTouching) {
var actuel = event.touches[0].pageY,
delta = debut - actuel;
if (Math.abs(delta) >= 30) { // this '30' is the length of the swipe
if (delta > 0) {
swipe.up();
} else {
swipe.down();
}
finGeste();
}
}
event.preventDefault();
}
});
};
})(jQuery);
这是利用部分:
$(document).tactile({
up: function() { },
down: function() { }
});
我不能保证这是正确的方式,这也不是好的代码,但它的工作原理。
是的,我做过了,我已经尝试了大部分我找到的图书馆,但是我没有真正找到一个效果不错的图书馆。 :( –