gpt4 book ai didi

sencha-touch - 在 Sencha Touch 中禁用轮播过度滚动/过度拖动

转载 作者:行者123 更新时间:2023-12-01 11:47:46 25 4
gpt4 key购买 nike

在 Sencha Touch 2 旋转木马的末尾或开头,用户可以将项目拖过它应该能够到达的位置并显示白色背景(此处的屏幕截图:http://i.imgur.com/MkX0sam.png)。我正在尝试禁用此功能,因此用户不能拖过轮播的结尾/开头。

我已经尝试使用各种可滚动配置来做到这一点,包括通常建议用于处理过度滚动的设置

scrollable : {
direction: 'horizontal',
directionLock: true,
momentumEasing: {
momentum: {
acceleration: 30,
friction: 0.5
},
bounce: {
acceleration: 0.0001,
springTension: 0.9999,
},
minVelocity: 5
},
outOfBoundRestrictFactor: 0
}

上面的配置,尤其是 outOfBoundRestrictFactor 确实阻止了拖过末端的能力,但它也阻止了拖拽轮播中其他任何地方的能力……所以这是行不通的。我搞砸了所有其他配置,但没有产生任何积极效果。

不幸的是,我没能找到很多关于修改拖动配置的信息。这里的任何帮助都会很棒。

最佳答案

您需要做的是覆盖 Carousel 中的 onDrag 功能。这是用于检测用户拖动方向的逻辑,您可以在此处检查它是第一项还是最后一项。

这是一个完全符合您要求的类。您感兴趣的代码就在函数的底部。其余的只是取自 Ext.carousel.Carousel

Ext.define('Ext.carousel.Custom', {
extend: 'Ext.carousel.Carousel',

onDrag: function(e) {
if (!this.isDragging) {
return;
}

var startOffset = this.dragStartOffset,
direction = this.getDirection(),
delta = direction === 'horizontal' ? e.deltaX : e.deltaY,
lastOffset = this.offset,
flickStartTime = this.flickStartTime,
dragDirection = this.dragDirection,
now = Ext.Date.now(),
currentActiveIndex = this.getActiveIndex(),
maxIndex = this.getMaxItemIndex(),
lastDragDirection = dragDirection,
offset;

if ((currentActiveIndex === 0 && delta > 0) || (currentActiveIndex === maxIndex && delta < 0)) {
delta *= 0.5;
}

offset = startOffset + delta;

if (offset > lastOffset) {
dragDirection = 1;
}
else if (offset < lastOffset) {
dragDirection = -1;
}

if (dragDirection !== lastDragDirection || (now - flickStartTime) > 300) {
this.flickStartOffset = lastOffset;
this.flickStartTime = now;
}

this.dragDirection = dragDirection;

// now that we have the dragDirection, we should use that to check if there
// is an item to drag to
if ((dragDirection == 1 && currentActiveIndex == 0) || (dragDirection == -1 && currentActiveIndex == maxIndex)) {
return;
}

this.setOffset(offset);
}
});

关于sencha-touch - 在 Sencha Touch 中禁用轮播过度滚动/过度拖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14410934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com