微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Jquery工具触摸水平仅禁用垂直触摸

我有jquery工具滚动…我喜欢它只为swipeLeft swipeRight实现触摸选项.

当我使用touch:true时,它也会在swipeUp / Down时旋转.

我按照说明在这里

07000

和这里:

07001

但似乎没有工作..任何想法?我的小提琴/演示在下面供参考

fiddle: 07002

demo: 07003

谢谢

解决方法

如果您使用的唯一控件是Scrollable,那么您可以从 here编辑它的源代码以修复该行为或根据您的需要调整它.

修改了您发布的fiddle,以在JavaScript代码部分中包含Scrollable控件的代码.

在控件的代码添加的行是在以下代码段的末尾添加注释//的行:

// 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();
            }
        };
    }

我已经在Android中尝试使用本机和Opera浏览器,并且似乎按预期工作.

原文地址:https://www.jb51.cc/jquery/180852.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐