Mon*_*sto 5 jquery scroll touch gesture swipe
我有jquery工具滚动...我喜欢它只为swipeLeft swipeRight实现触摸选项.
当我使用touch:true时,它也会在swipeUp/Down时旋转.
我按照这里的说明:
和这里:
http://awardwinningfjords.com/2010/09/22/handling-touch-events-in-jquery-tools-scrollable.html
但似乎没有工作..任何想法?我的小提琴/演示在下面供参考
谢谢
如果您使用的唯一控件是Scrollable,那么您可以从此处编辑它的源代码以修复该行为或根据您的需要调整它.
我修改了你发布的小提琴,在代码部分包含了Scrollable控件的JavaScript代码.
控件代码中添加的行// added是以下代码段末尾带注释的行:
// touch event
if (conf.touch) {
var touch = {};
itemWrap[0].ontouchstart = function(e) {
var t = e.touches[0];
touch.x = t.clientX;
touch.y = t.clientY;
};
itemWrap[0].ontouchmove = function(e) {
// only deal with one finger
if (e.touches.length == 1 && !itemWrap.is(":animated")) {
var t = e.touches[0],
deltaX = touch.x - t.clientX,
deltaY = touch.y - t.clientY,
absX = Math.abs(deltaX), // added
absY = Math.abs(deltaY); // added
// Only consider the event when the delta in the
// desired axis is greater than the one in the other.
if(vertical && absY > absX || !vertical && absX > absY) // added
self[vertical && deltaY > 0 || !vertical && deltaX > 0 ? 'next' : 'prev']();
e.preventDefault();
}
};
}
Run Code Online (Sandbox Code Playgroud)
我在Android中尝试使用本机和Opera浏览器,似乎按预期工作.