首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >暂时允许使用TouchSwipe插件进行垂直滚动

暂时允许使用TouchSwipe插件进行垂直滚动
EN

Stack Overflow用户
提问于 2012-10-22 16:26:00
回答 2查看 8.8K关注 0票数 4

我使用SwipeTouch plugin通过滑动来隐藏和显示#child元素。

我有一个包含#child元素的#parent元素。

#child并不总是有足够的内容来创建滚动条,但是当存在is.The #parent约束#child元素时就会出现问题,如果#child元素比#parent高,则强制使用滚动条

<div id="parent">
    <div id="child">
         <!-- Lots of content -->
    </div>
</div>​

我想允许在任何方向滑动来显示和隐藏#child

swipeIN.

  • Swiping to
  • #child element将称为swipeIN.
  • Swiping to hide #child element将称为swipeOUT.

...的问题是,如果滚动条存在并且#child是可见的,我不能垂直滚动,因为这会注册为滑动尝试并触发swipeOUT

所以,我有一个计划:

swipeOUT.

  • Scrollbars:

  • No scrollbar:向所有方向滑动触发swipeIN,向所有方向滑动触发swipeIN。向上或向下滑动可滚动,向左或向右滑动可触发swipeOUT.

这是一个很好的计划,只是它行不通。我想如果我能够暂时禁用顶部滑动和向下滑动,它就会起作用…

Link to my attempt (这个问题只在触摸设备上才明显)。

Link that is better for testing in a touch device

你有什么办法让它工作吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-24 15:36:14

我开始思考我自己项目的长期计划,一段时间前,我终于让自己通过github(链接github问题页面)联系到了插件的开发者。

他更新了插件,以便您现在可以动态更改所有插件选项。这也使得我所寻找的行为成为可能。有关这方面的文档可以在here (该方法名为:option )中找到。

http://jsfiddle.net/lollero/yATmM/

http://jsfiddle.net/lollero/yATmM/show

我的代码:

$(function() {      

    $(".parent").each(function() {

        var obj = $(this),
            objD = obj.data(),
            objChild = obj.find('.child'),
            scrollbars = obj.height() < objChild.height();

        obj
        .data({ "swipe": "in" })
        .swipe({

            fallbackToMouseEvents: true,
            swipe:function( event, direction ) {

                // swipeIN = swipe that shows #child 
                // ( Swiping is allowed for all directions ).
                if ( objD.swipe === 'in' ) {

                    obj.data({ "swipe": "out" });
                    objChild.show();

                    // If scrollbar exists, set allowPageScroll data 
                    // to 'vertical', so that next time when you swipe 
                    // up or down, you can scroll vertically.
                    scrollbars && obj.swipe('option', 'allowPageScroll', 'vertical');

                }
                // swipeOUT = swipe that hides#child 
                // If scrollbars don't exist, swipe at any direction to hide.
                // If scrollbars exits, swipe left or right to hide ( Up and Down is reserved for scrolling ).
                else if ( 
                    objD.swipe === 'out' && scrollbars && ( direction === 'left' || direction === 'right' )  || 
                    objD.swipe === 'out' && !scrollbars
                ) {

                    obj.data({ "swipe": "in" });
                    objChild.hide();

                    // If scrollbar exists, set allowPageScroll data to
                    // false, so that next time when you swipe up or down,
                    // you actually trigger a swipe.
                    scrollbars && obj.swipe('option', 'allowPageScroll', false );

                }

            }

        });

    });

});
票数 2
EN

Stack Overflow用户

发布于 2013-03-15 20:08:54

将选项'allowPageScroll‘从'auto’(默认值)设置为'vertical‘(在某些情况下,如果你愿意的话)应该可以解决这个问题

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13007499

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档