ページの最初と最後でカルーセルのスワイプを停止したい。終了ページが右にスワイプし、開始ページが左にスワイプし
ないようにすることを意味します。
それを実装するための構成または他の方法はありますか?
前もって感謝します。
ページの最初と最後でカルーセルのスワイプを停止したい。終了ページが右にスワイプし、開始ページが左にスワイプし
ないようにすることを意味します。
それを実装するための構成または他の方法はありますか?
前もって感謝します。
独自のカルーセルを作成し、次のコード形式で 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);
}
});
参照 :=リンク
デフォルトでは、ST2 のcarousel
コンポーネントはこの構成になっています。したがって、これを達成するために余分な努力をする必要はありません。
this
Sencha の 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'
}
]
});