Sencha touch Sencha Touch 2转盘:开始/结束页面的锁定滑动

Sencha touch Sencha Touch 2转盘:开始/结束页面的锁定滑动,sencha-touch,sencha-touch-2,carousel,swipe,Sencha Touch,Sencha Touch 2,Carousel,Swipe,我希望旋转木马停止在页面的开头和结尾滑动。 我的意思是防止结束页面向右滑动和开始页面向左滑动: 是否有任何配置或其他方式来实现它 提前感谢。默认情况下,ST2的组件具有此配置。因此,您无需付出任何额外的努力来实现这一点 看看Sencha网站上的例子。当您到达最后一个项目时,它将阻止向右滑动,当您位于第一个项目时,它将阻止向左滑动 Ext.create('Ext.Carousel', { fullscreen: true, defaults: { styleHt

我希望旋转木马停止在页面的开头和结尾滑动。
我的意思是防止结束页面向右滑动和开始页面向左滑动:

是否有任何配置或其他方式来实现它

提前感谢。

默认情况下,ST2的组件具有此配置。因此,您无需付出任何额外的努力来实现这一点

看看Sencha网站上的例子。当您到达最后一个项目时,它将阻止向右滑动,当您位于第一个项目时,它将阻止向左滑动

Ext.create('Ext.Carousel', {
    fullscreen: true,

    defaults: {
        styleHtmlContent: true
    },

    items: [
        {
            html : 'Item 1',
            style: 'background-color: #5E99CC'
        },
        {
            html : 'Item 2',
            style: 'background-color: #759E60'
        },
        {
            html : 'Item 3'
        }
    ]
});

您可以创建自己的旋转木马,然后覆盖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);
    }
});
Ext.define('Ext.carousel.Custom'{
扩展:“Ext.carousel.carousel”,
onDrag:函数(e){
如果(!this.isDraging){
返回;
}
var startOffset=this.dragstartfset,
方向=this.getDirection(),
delta=方向===‘水平’?e.deltaX:e.deltaY,
lastOffset=此.offset,
flickStartTime=this.flickStartTime,
dragDirection=this.dragDirection,
now=Ext.Date.now(),
currentActiveIndex=this.getActiveIndex(),
maxIndex=this.getMaxItemIndex(),
lastDragDirection=dragDirection,
抵消;
如果((currentActiveIndex==0&&delta>0)| |(currentActiveIndex==maxIndex&&delta<0)){
δ*=0.5;
}
偏移量=STARTOFSET+增量;
如果(偏移>上次偏移){
牵引方向=1;
}
否则如果(偏移量<上次偏移量){
拖动方向=-1;
}
如果(dragDirection!==lastDragDirection | |(现在-flickStartTime)>300){
this.flickStartOffset=lastOffset;
this.flickStartTime=now;
}
this.dragDirection=dragDirection;
//现在我们有了dragDirection,我们应该使用它来检查是否有
//是要拖动到的项目
if((dragDirection==1&¤tActiveIndex==0)| |(dragDirection==1&¤tActiveIndex==maxIndex)){
返回;
}
这个.setOffset(offset);
}
});

参考资料:=

感谢您的回复。也许我没有确切地解释我想要什么。对于最后一张卡,它会向右刷卡,但会自动向后刷卡并防止刷卡。好啊但我不想要这个。我甚至不想刷到右边然后再回去。我想“锁定”刷最后一张卡。在上面的示例中,当我在“项目1”卡上向左滑动时,我不希望看到白色背景。我能解释一下我想要什么吗?提前感谢。请查看此可锁定旋转木马类: