我使用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
.
#child
element将称为swipeIN
.#child
element将称为swipeOUT
....的问题是,如果滚动条存在并且#child
是可见的,我不能垂直滚动,因为这会注册为滑动尝试并触发swipeOUT
。
所以,我有一个计划:
swipeOUT
.
swipeIN
,向所有方向滑动触发swipeIN
。向上或向下滑动可滚动,向左或向右滑动可触发swipeOUT
.
这是一个很好的计划,只是它行不通。我想如果我能够暂时禁用顶部滑动和向下滑动,它就会起作用…
Link to my attempt (这个问题只在触摸设备上才明显)。
Link that is better for testing in a touch device
你有什么办法让它工作吗?
发布于 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 );
}
}
});
});
});
发布于 2013-03-15 20:08:54
将选项'allowPageScroll‘从'auto’(默认值)设置为'vertical‘(在某些情况下,如果你愿意的话)应该可以解决这个问题
https://stackoverflow.com/questions/13007499
复制相似问题