禁用特定div上的滑动 [英] Disabling swipe on a specific div

查看:79
本文介绍了禁用特定div上的滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有此jQuery Mobile 1.9.1代码,可以在用户向右或向左滑动时照顾显示侧面板的情况.

Having this jQuery Mobile 1.9.1 code, to take care of showing side panels when the user swipes right or left...

$(document).on("pageinit",".ui-page",function(){

    var $page=$(this);
    $page.on("swipeleft swiperight",function(e){
        if($page.jqmData("panel")!=="open"){
            if(e.type==="swiperight"){
                $page.find("#menu").panel("open");
            }else if(e.type==="swipeleft"){
                $page.find("#menu2").panel("open");
            }
        }
    });
});

在使用具有滑动功能的图像滑块时会产生问题.当我向右滑动时,在滑块div内,它会更改为下一张照片并打开面板...

This creates a problem when using an image slider with swiping capabilities. Inside the slider div when I swipe right it changes to the next photo and opens the panel...

我只是尝试这样做:

    $('#full-width-slider').swipe(function(e){
        e.stopPropagation();
        e.preventDefault();
    });

但它根本不起作用.

有什么方法可以禁用div#full-width-slider中的jQuery Mobile本机幻灯片功能吗?

Is there any way to disable the jQuery Mobile native slide function inside the div #full-width-slider ?

谢谢.

推荐答案

.on('swipeleft swiperight', function(e){

相对于

.swipe(function(e){

虽然我对这个答案不是100%充满信心,但是感觉试验表明,代码仍然存在问题,您可能必须对原始元素进行完整性检查,例如

While I'm not 100% confident in this answer, a feel trials revealed that there will still be issues with the code and you might have to do a sanity check in the original element, something like,

if($.inArray('full-width-slider', $.trim($(e.target).prop('id')).split(' ')) > -1){
    //full with slider is the target, so return out 
}

这篇关于禁用特定div上的滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆