1

ページの最初と最後でカルーセルのスワイプを停止したい。終了ページが右にスワイプし、開始ページが左にスワイプ
ないようにすることを意味します。

カルーセル

それを実装するための構成または他の方法はありますか?

前もって感謝します。

4

2 に答える 2

1

独自のカルーセルを作成し、次のコード形式で 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);
    }
});

参照 :=リンク

于 2014-03-20T09:26:30.717 に答える
1

デフォルトでは、ST2 のcarouselコンポーネントはこの構成になっています。したがって、これを達成するために余分な努力をする必要はありません。

thisSencha の Web サイトの例を見てください。最後のアイテムに到達すると、右へのスワイプが防止され、最初のアイテムに到達すると、左へのスワイプが防止されます。

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'
        }
    ]
});
于 2012-06-07T17:04:58.943 に答える